Skip to content

Instantly share code, notes, and snippets.

@zombiezen
Created December 24, 2016 06:33
Show Gist options
  • Save zombiezen/f621f924cc5d7b355f245d721ba5ff27 to your computer and use it in GitHub Desktop.
Save zombiezen/f621f924cc5d7b355f245d721ba5ff27 to your computer and use it in GitHub Desktop.
Weird bash parameter expansion test behavior
#!/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