bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

set -x and parameter expansion


From: Peggy Russell
Subject: set -x and parameter expansion
Date: Mon, 14 Mar 2011 00:06:28 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

I got the expected results below, but I didn't get the expected
expansion in case (3).

I expected to see "+ [[ 0 -eq 0 ]]" and not "+ [[ 0 -eq r ]]".

With set -x, aren't the left and right parameters in a expression
the final result of all expansions, including arithmetic expansion?
Isn't that enough to change r to 0 in case (3)?

(1)
set -xv
declare r=0
/bin/true; if [ $? -eq r    ]; then echo "1 Y";else echo "N";fi
...
+ '[' 0 -eq r ']'
./t3: line 12: [: r: integer expression expected
+ echo N

(2)
/bin/true; if [ $? -eq $r   ]; then echo "2 Y"; else echo "N";fi
...
+ '[' 0 -eq 0 ']'
+ echo '2 Y'

(3)
/bin/true; if [[ $? -eq r  ]]; then echo "3 Y"; else echo "N";fi
...
+ [[ 0 -eq r ]]  <-----
+ echo '3 Y'

(4)
/bin/true; if [[ $? -eq $r ]]; then echo "4 Y"; else echo "N";fi
...
+ [[ 0 -eq 0 ]]
+ echo '4 Y'

(Similar to 3)
unset r a; a=0; declare -i r=a
/bin/true; if [[ $? -eq r  ]]; then echo "5 Y"; else echo "N";fi
...
+ [[ 0 -eq r ]]  <-----
+ echo '2 Y'

Thank you.
Peggy Russell




reply via email to

[Prev in Thread] Current Thread [Next in Thread]