Bash 在if测试中使用变量作为运算符
我试图在Bash 在if测试中使用变量作为运算符,bash,shell,Bash,Shell,我试图在if测试中使用变量作为运算符 if [[ $action = "active" ]];then operator="-le" fi if [[ $Apps $operator 100 ]];then echo "No of apps $Apps" fi 我在“附近遇到语法错误。您可以切换到[,在shell展开所有参数之前,它不会看到其参数。[[必须在展开$operator之前进行完全解析,并且它需要看到实际的运算符 if [ "$Apps" "$operator
if
测试中使用变量作为运算符
if [[ $action = "active" ]];then
operator="-le"
fi
if [[ $Apps $operator 100 ]];then
echo "No of apps $Apps"
fi
我在“附近遇到语法错误。您可以切换到
[
,在shell展开所有参数之前,它不会看到其参数。[[
必须在展开$operator
之前进行完全解析,并且它需要看到实际的运算符
if [ "$Apps" "$operator" 100 ]; then
echo "No of apps $Apps"
fi
您是否尝试过嵌套的
if
运算符
if [ "$action" = "active" ]
then if [ "$Apps" -eq 100 ]
....
接近什么?接近`?你的代码中没有反勾号。谢谢你的回复。因为其他代码。我必须分开做。但是单括号有效