我一直在尝试为我的bash shell脚本添加一个选项,有人做了“-r”我推送到git服务器但是我收到以下错误
mirror.sh: line 8: conditional binary operator expected
mirror.sh: line 8: syntax error near `-e'
mirror.sh: line 8: `if [[ "$1" -e "-r" ]];then'
下面是我的bash脚本:
#!/bin/bash
cd /home/joe/Documents/sourcecode/mirror.git
git svn rebase
#
# if option -r then push to master
#
if [[ "$1" -e "-r" ]];then
git push origin master
fi
答案 0 :(得分:1)
尝试:
if [[ "$1" = "-r" ]];then
或
if [[ "$1" == "-r" ]];then
答案 1 :(得分:0)
怎么样:
if [[ "$1" == "-r" ]]; then
-e在您的示例测试中是否存在文件。这是错误的。
答案 2 :(得分:0)
如上所述-e
确实是file existence test。我想您想要比较使用-eq
的值和想法,但这是arithmetic binary operator。您需要==
将字符串比较为
if [[ "$1" == "-r" ]];