Reputation: 39014
The function below was originally a bash function. I need it to run in busybox 1.22 ash
shell.
dockerip() {
if (( $# != 1 ))
then
for d in $(docker ps -q)
do
name=$(docker inspect -f {{.Name}} $d)
ip=$(docker inspect -f {{.NetworkSettings.IPAddress}} $d)
printf "%-15s | %15s\n" $name $ip
done
fi
}
When the code above is loaded with source
and run as dockerip
the busybox shell outputs: sh: 0: not found
. Not a very helpful error so my question is what does the error mean and what part(s) of the function above aren't busybox 1.22 compatible?
Upvotes: 0
Views: 1846
Reputation: 247052
This arithmetic expression (( $# != 1 ))
is bash syntax. In ash, it's launching 2 nested subshells, then executing the program "$#" with arguments "!=" and "1".
Use this instead
if [ $# -ne 1 ]
Upvotes: 3