I have an Asus router running a recent version of FreshTomato - that comes with BusyBox.
I need to run a script that was made with BASH in mind - it is an adaptation of this script - but it fails to run with this error: line 41: syntax error: bad substitution
Checking the script with shellcheck.net yields these errors:
Line 41:
for optionvarname in ${!foreign_option_*} ; do
^-- SC3053: In POSIX sh, indirect expansion is undefined.
^-- SC3056: In POSIX sh, name matching prefixes are undefined.
Line 42:
option="${!optionvarname}"
^-- SC3053: In POSIX sh, indirect expansion is undefined.
These are the lines that are causing problems:
for optionvarname in ${!foreign_option_*} ; do # line 41
option="${!optionvarname}" # line 42
# do some stuff with $option...
done
If my understanding is correct, the original script simply does something with all variables that have a name starting with foreign_option_
However, as far as I could determine, both ${!foreign_option_*}
and ${!optionvarname}
constructs are BASH-specific and not POSIX compliant, so there is no direct "bash to sh" code conversion possible.
I have tried to create a /bin/bash
symlink that points to busybox
, but I got the Read-only file system
error.
So, how can I get this script to run on my router? I see only two options, but I cant figure out how to implement either:
- Make BusyBox interpret the script as BASH instead of SH - can I use a specific shebang for this?
- Seems like the fastest option, but only if BusyBox has a "complete" implementation of BASH
- Alter the script code to not use BASH specifics.
- This is safer, but since there is no "collect al variables starting with X" for SH, how can I do it?