我有一个带有.sh
扩展的shell脚本,并在OSX环境中运行,我在其中设置了一个变量,如下所示:
booean_var1 = false
booean_var2 = true
并且有一个基于 2 个变量的 if 检查
if [ $booean_var1 ] || [ $booean_var2 ]
then
echo one of them is true
fi
在一台OSX机器上的bash上运行它可以正常工作。但是我从另一台OSX机器上执行了我的shell脚本并从那里在bash上运行它说
booean_var1 command not found
shell脚本语法与一台机器到另一台机器的bash不同吗?
尝试不带空格:
booean_var1=false
booean_var2=true
因为true
和false
是命令:
which true false
/bin/true
/bin/false
你可以简单地将括号[
,]
:
if $booean_var1 || $booean_var2 ;then
echo one of them is true
fi
booean_var1=false
booean_var2=true
if [ "$booean_var1" = true ] || [ "$booean_var2" = true ]
then
echo one of them is true
fi