Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.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无法正确比较字符串_Bash_Braces - Fatal编程技术网

Bash无法正确比较字符串

Bash无法正确比较字符串,bash,braces,Bash,Braces,这是我的bash文件 #!/bin/sh ENV=DEV echo "env: $ENV" if [[ "$ENV" == DEV* ]]; then RUNTIME_CLASSPATH=$(cat ../build/dev.classpath) echo "cp: $RUNTIME_CLASSPATH" fi echo "done" 这是终端输出: ~proj/bin$ ./test.sh env: DEV ./test.sh: 7: [[: not found done

这是我的bash文件

#!/bin/sh
ENV=DEV
echo "env: $ENV"
if [[ "$ENV" == DEV* ]]; then
    RUNTIME_CLASSPATH=$(cat ../build/dev.classpath)
    echo "cp: $RUNTIME_CLASSPATH"
fi
echo "done"
这是终端输出:

~proj/bin$ ./test.sh 
env: DEV
./test.sh: 7: [[: not found
done
我不明白怎么了。是否有其他方法进行字符串比较?

更改

if [[ "$ENV" == DEV* ]]; then

.改变

if [[ "$ENV" == DEV* ]]; then


.

如果要编写bash脚本,则不要编写POSIX shell脚本:将shebang行更改为:

#!/bin/bash
另一方面,如果要编写可移植的shell脚本,请使用
case
语句:

case "$ENV" in 
  DEV*)
    RUNTIME_CLASSPATH=$(cat ../build/dev.classpath)
    echo "cp: $RUNTIME_CLASSPATH"
    ;;
esac

如果要编写bash脚本,则不要编写POSIX shell脚本:将shebang行更改为:

#!/bin/bash
另一方面,如果要编写可移植的shell脚本,请使用
case
语句:

case "$ENV" in 
  DEV*)
    RUNTIME_CLASSPATH=$(cat ../build/dev.classpath)
    echo "cp: $RUNTIME_CLASSPATH"
    ;;
esac

虽然这段代码片段可能会解决这个问题,包括如何以及为什么解决这个问题的解释,以提高您的文章的质量。记住,你是在将来回答读者的问题,而不仅仅是现在提问的人!请在回答中添加解释,并说明适用的限制和假设。而此代码片段可能会解决问题,包括解释如何以及为什么解决问题以提高帖子质量。记住,你是在将来回答读者的问题,而不仅仅是现在提问的人!请在回答中添加解释,并说明适用的限制和假设。