15 Nov
2008
15 Nov
'08
05:26
Listmates,
Stuck on a stupid bash problem again. Why can't I set a variable within a set of parenthesis?
#!/bin/bash
# This works
[[ $1 == "--verbose" || $1 == "-v" ]] && verbose='y'
[[ $1 == "--verbose" || $1 == "-v" ]] && ( echo "this"; echo "that" )
# This _doesn't_ work
[[ $1 == "--verbose" || $1 == "-v" ]] && ( verbose='y'; echo "that" )
No matter what I do, if I try to set a variable inside the ( ) expression, it never gets set -- Why? Because commands enclosed withing "( ..... )" get run in a subshell, where the
On Friday 14 November 2008 20:54:16 David C. Rankin wrote: the variable "verbose" is indeed set to "y" and then immediately discarded when the subshell exits. -- Jim