----- Original Message -----
From: "David C. Rankin"
Randall R Schulz wrote:
On Friday 14 November 2008 20:54, David C. Rankin wrote:
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?
What Jim Cunning said is correct.
However, there is another similar kind of command grouping syntax that does not cause the creation of a sub-shell: the { curly brace }. Side-effect on local variables and shell options made within this construct _do_ persist outside / beyond it.
-- David C. Rankin
Randall Schulz
Randall,
I will have to try that again. I thought something similar to brace expansion was correct, like awk '{ do this/that }', but the last time I tried (and I tried a lot), BASH kept complaining about my syntax (not a uncommon happening), I'll give it another go.
commands in braces need to be terminated by a linefeed or a semicolon before the close brace. { echo this echo is echo ok } { echo this ; echo is ; echo ok ; } { echo this ; echo is ; echo not } -- Brian K. White brian@aljex.com http://www.myspace.com/KEYofR +++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++. filePro BBx Linux SCO FreeBSD #callahans Satriani Filk! -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org