[英]error sh: 0: not found while converting bash function to sh
下面的函数原本是bash函数。 我需要它在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
}
当上面的代码加载source
并以dockerip
运行时,busybox shell输出: sh: 0: not found
。 这不是一个非常有用的错误,所以我的问题是错误是什么意思,并且上面功能的哪些部分与busybox 1.22不兼容?
此算术表达式(( $# != 1 ))
是bash语法。 在ash中,它将启动2个嵌套的子shell,然后执行带有参数“!=”和“ 1”的程序“ $#”。
改用这个
if [ $# -ne 1 ]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.