Busybox test no longer working properly

I upgraded from r23611 to r23885. I changed busybox "Test builtin" to off.
One of my scripts isn't working anymore:

# [[ -r /tmp/ddns_ip ]] ; echo $?
0
# [[ -w /tmp/ddns_ip ]] ; echo $?
0
# [[ -r /tmp/ddns_ip && -w /tmp/ddns_ip ]] ; echo $?
[[: missing ]]
2

Is this a bug or am I doing something really stupid at this late hour of the night?
Thanks!

[[ is an alias for the busybox test command. Does single bracket still work?

I know it's the same, that's why I mentioned that change.
Single bracket doesn't work. AFAIK, it's also the same as test and double bracket.

https://www.shellcheck.net/wiki/SC2107

3 Likes

[[ is a bashism and not defined in POSIX shell, don't use it.

7 Likes

Thank you both. I didn't know that. I always thought that [[ is a more advanced version of [ and that busybox uses [[ for both.

I wonder why it worked with "Test builtin" config option? Or maybe there was some other change that I made?

Maybe this works?

[[ -r /tmp/ddns_ip && -w /tmp/ddns_ip ]]  && echo $?

There is no reason not to use:

if [ -r /tmp/ddns_ip ] && [ -w /tmp/ddns_ip ]; then
    echo 0 1>&2
else
    echo 1 1>&2
fi

and keep it POSIX compliant.

2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.