Bash脚本缺less']'
我得到一个错误./test.sh:第13行:[:缺less`]'在test.sh文件中我尝试使用括号和其他选项,如-a或通过检查文件的大小,但错误是总是在那里,其他语句总是被执行,而不pipe给定的input。我甚至试图通过删除; 在13行,但没有帮助。
test.sh
#!/bin/bash echo "Enter app name" read y $y & top -b -n 1 > topLog.log #-w checks for the whole word not and sub string from that word grep -w "$y" topLog.log > p1 #-s option checks if the file p1 is present or not if [ -s "p1"]; #line 13 then echo "Successful " else echo "Unsuccessful" fi rm p1 我是bash脚本的新手,所以如果有什么愚蠢的错误,请原谅我。
更改
 if [ -s "p1"]; #line 13 
成
 if [ -s "p1" ]; #line 13 
注意空间。
 您在"p1"之后缺less空格: 
 if [ -s "p1" ]; 
 我试图在单个括号内使用&&运算符,例如[ ... && ... ]我得到这个错误。 我不得不切换到[[ ... && ... ]] 。 
在右括号之前添加一个空格