Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 在if测试中使用变量作为运算符_Bash_Shell - Fatal编程技术网

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 ]
....

接近什么?接近`?你的代码中没有反勾号。谢谢你的回复。因为其他代码。我必须分开做。但是单括号有效