shell if [ ]的问题
ifgrep "xiuxian" /etc/bash.bashrc ; thenecho aa
# sed -i 's/*export*xiuxian*/#export LD_LIBRARY_PATH=/usr/local/lib/xiuxian:\$LD_LIBRARY_PATH/g' /etc/bash.bashrc
# [ $? -eq 0 ] && echo "sed xiuxian success" >>/tmp/restore.log
fi
在suse 写一个小脚本 if 在通过grep 作为条件的时候不能有[ ] 否则报错line 2: [: xiuxian: binary operator expected
==========================这一段是网上别人遇到的错误 和解决方法+++
今天写了个shell脚本一运行就出现"binary operator expected"错误
test1.sh: line 6: [: /export/images/a10091400ux0415: binary operator expected
检查脚本第六行:
if [ ! -f /export/images/$line ];then
上网查了一下,加上双引号,就可以了
将 if [ ! -f /export/images/$line ];then 改为
if [ ! -f "/export/images/$line" ];then
问题解决.
来源地址 : http://tangyou.me/binary-operator-expected-shell-script-error.html
=====================================
页:
[1]