[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: variable name and its' value are the same characters causes recursio
From: |
Peggy Russell |
Subject: |
Re: variable name and its' value are the same characters causes recursion error |
Date: |
Tue, 8 Mar 2011 04:48:36 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
> Since those are not numeric, bash treats them as expressions to be
> evaluated. You don't have to use the $ to obtain variable evaluation
> when using [[ or [. You get:
c=1;a="c";b=2;[[ a -lt b ]]; echo $?
0
c=3;a="c";b=2;[[ a -lt b ]]; echo $?
1
I see. I was aware of explicit indirection as described in the man page section
"Parameter Expansion", with the syntax ${!name}. I wasn't aware of the above
implicit indirection with [[ expression ]].
But, for [ expression ], I have to use explicit indirection with ${!a} otherwise
I get an error, "bash: [: a: integer expression expected".
This brings up some interesting situations with indirection and declare:
# f is assigned the value of z through implicit indirection
unset z f;declare -i z=5;declare -i f="z";declare -p z f
declare -i z="5"
declare -i f="5"
# f is assigned the default value of 0 when z is not defined
# for implicit indirection
unset z f;declare -i f="z";declare -p z f
bash: declare: z: not found
declare -i f="0"
# f is assigned the default value of 0 when empty variable name
# is used for implicit indirection
unset z f;declare -i f="";declare -p z f
bash: declare: z: not found
declare -i f="0"
#
unset z f;declare -i f;echo $?;echo \"$f\";declare -p z f
0
""
bash: declare: z: not found
bash: declare: f: not found
It would be helpful if indirection was explained in the documentation for
[[ expression ]], [ expression ], and declare.
Thank you.
Peg
- variable name and its' value are the same characters causes recursion error, Peggy Russell, 2011/03/07
- Re: variable name and its' value are the same characters causes recursion error, Chet Ramey, 2011/03/07
- Re: variable name and its' value are the same characters causes recursion error,
Peggy Russell <=
- Re: variable name and its' value are the same characters causes recursion error, Chet Ramey, 2011/03/09
- Re: variable name and its' value are the same characters causes recursion error, Peggy Russell, 2011/03/09
- Re: variable name and its' value are the same characters causes recursion error, Chet Ramey, 2011/03/09
- Re: variable name and its' value are the same characters causes recursion error, Eric Blake, 2011/03/09
- Re: variable name and its' value are the same characters causes recursion error, Chet Ramey, 2011/03/09
- Re: variable name and its' value are the same characters causes recursion error, Clark J. Wang, 2011/03/09
- Re: variable name and its' value are the same characters causes recursion error, Clark J. Wang, 2011/03/09
- Re: variable name and its' value are the same characters causes recursion error, Greg Wooledge, 2011/03/10
- Re: variable name and its' value are the same characters causes recursion error, Chet Ramey, 2011/03/10
- Re: variable name and its' value are the same characters causes recursion error, Maarten Billemont, 2011/03/11