[英]Bash not comparing strings properly
這是我的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腳本,則不要編寫POSIX shell腳本:將shebang行更改為:
#!/bin/bash
另一方面,如果要編寫可移植的shell腳本,請使用case
語句:
case "$ENV" in
DEV*)
RUNTIME_CLASSPATH=$(cat ../build/dev.classpath)
echo "cp: $RUNTIME_CLASSPATH"
;;
esac
更改
if [[ "$ENV" == DEV* ]]; then
至
if [ "$ENV" == "DEV" ]; then
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.