我一直在尝试向我的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发布于 2013-02-14 20:57:20
下面是什么:
if [[ "$1" == "-r" ]]; then示例中的-e测试文件是否存在。这是错误的。
发布于 2013-02-14 20:53:14
尝试:
if [[ "$1" = "-r" ]];then
或
if [[ "$1" == "-r" ]];then
发布于 2013-02-14 21:06:37
如上所述,-e确实是一个file existence test。我猜您想要比较值并考虑使用-eq,但这是一个arithmetic binary operator。您需要==将字符串比较为
if [[ "$1" == "-r" ]];https://stackoverflow.com/questions/14875251
复制相似问题