ash: question about using test with '=' as $1

Bastian Bittorf bittorf at bluebottle.com
Sun Oct 4 17:49:05 UTC 2015


while discussing a shellsheck issue[1], i stumpled
upon an interesting behaviour which is weird and
i cannot find it to be a problem when reading POSIX[2]
here, but all tested shells (ash,dash,bash) somehow
break at this:

user at box:~ x='='
user at box:~ test -n "$x" -a 1 -eq 1
ash: 1: unknown operand

but this works:

user at box:~ test -n "$x" 
user at box:~ echo $?
0
user at box:~ test -z "$x" 
user at box:~ echo $?
1

the problem is using -a or -o which
is "unspecified" according to posix, but...really?

bye, bastian

[1] https://github.com/koalaman/shellcheck/issues/489
[2] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html


More information about the busybox mailing list