I am trying to check for a single period '.' in a shell variable.
$ I=. $ echo $I . $ if [[ "$I" -eq '.' ]]; then echo true; fi -bash: [[: .: syntax error: operand expected (error token is ".")
All other variants of this construct, with and without escape characters, single and double quote combinations, that I can think of all give exactly the same error.
How does one check to see for this in a bash script?
On Thu, 28 Jul 2011, James B. Byrne wrote:
I am trying to check for a single period '.' in a shell variable.
$ I=. $ echo $I . $ if [[ "$I" -eq '.' ]]; then echo true; fi
if [ "$I" = '.' ]; then ...
Use a single = rather than -eq (which tests numeric equality) and use single brackets -- or, better, call test directly:
if test "$I" = '.'; then ...
"help test" is your friend!