Package: dash Version: 0.5.7-4+b1 Severity: normal In Bourne shell script with dash, using either [ ] or test,
test -n "${variable}" && echo "variable is set to -->${variable}<--" works as expected even if the value of variable is to a value the same as a test operator eg -ne or -nt variable="-ne" ; test -n "${variable}" && echo "variable is set to -->${variable}<--" variable is set to -->-ne<-- However the addition of another test condition with -a or -o results in an unexpected behavior in that the expanded variable is now treated as an operator and not just as the string as should be the case. variable="-ne" ; test -n "${variable}" -a -n "${DISPLAY}" && echo "variable is set to -->${variable}<--" dash: 1: test: Illegal number: -n Applying quoted parentheses makes no difference. variable="-ne" ; test \( -n "${variable}" \) -a \( -n "${DISPLAY}" \) && echo "variable is set to -->${variable}<--" dash: 2: test: Illegal number: -n Similarly bad behavior is seen with a variable set to "-nt", which is how I stumbled upon this problem. variable="-nt" ; test \( -n "${variable}" \) -a \( -n "${DISPLAY}" \) && echo "variable is set to -->${variable}<--" dash: 3: test: closing paren expected So if the test is consists of a single condtion, the expanded variable does not cause problems with the test, and should not affect the test if it is part of a multiple condition test. Incidentally bash also has this problem. So the short term kludge in a shell script is to do if [ -n "${variable_with_problem_value}" ] then if [ \( other_condition1 \) -a \( other_condition2 \) ] then ... -- System Information: Debian Release: 8.6 APT prefers stable-updates APT policy: (500, 'stable-updates'), (500, 'stable') Architecture: armel (armv5tel) Kernel: Linux 3.16.0-4-kirkwood Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=ANSI_X3.4-1968) (ignored: LC_ALL set to C) Shell: /bin/sh linked to /bin/dash Init: systemd (via /run/systemd/system) Versions of packages dash depends on: ii debianutils 4.4+b1 ii dpkg 1.17.27 ii libc6 2.19-18+deb8u6 dash recommends no packages. dash suggests no packages. -- debconf information: * dash/sh: true