Created
December 24, 2016 06:33
-
-
Save zombiezen/f621f924cc5d7b355f245d721ba5ff27 to your computer and use it in GitHub Desktop.
Weird bash parameter expansion test behavior
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
bash --version | |
# My repro is on GNU bash, version 4.3.30(1)-release (x86_64-pc-linux-gnu) | |
echo | |
echo "unset" | |
test 'foo123' -eq 0 && echo "test: true" || echo "test: false" | |
[ 'foo123' -eq 0 ] && echo "[: true" || echo "[: false" | |
[[ 'foo123' -eq 0 ]] && echo "[[: true" || echo "[[: false" | |
echo | |
echo "=0" | |
foo123=0 | |
test 'foo123' -eq 0 && echo "test: true" || echo "test: false" | |
[ 'foo123' -eq 0 ] && echo "[: true" || echo "[: false" | |
[[ 'foo123' -eq 0 ]] && echo "[[: true" || echo "[[: false" | |
echo | |
echo "=1" | |
foo123=1 | |
test 'foo123' -eq 0 && echo "test: true" || echo "test: false" | |
[ 'foo123' -eq 0 ] && echo "[: true" || echo "[: false" | |
[[ 'foo123' -eq 0 ]] && echo "[[: true" || echo "[[: false" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment