Bash脚本缺少“]" [英] Bash scripting missing ']'
本文介绍了Bash脚本缺少“]"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到一个错误./test.sh:行13:[:缺少`.]在文件test.sh中 我尝试使用方括号和其他选项(例如-a),或者通过检查文件p1的大小来尝试,但错误始终存在,并且无论给出的输入如何,始终执行else语句.我什至尝试通过删除;在第13行中,但这没有帮助.
I am getting an error ./test.sh: line 13: [: missing `]' in the file test.sh I tried using brackets and other options such as -a or by checking the size of the file p1 but the error is always there and the else statement is always executed irrespective of the input given.I even tried by removing the ; in line 13 but it didn't help.
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脚本的新手.所以,如果有任何愚蠢的错误,请原谅.
I am new to bash scripting.So if there is any silly mistake please excuse me.
推荐答案
更改
if [ -s "p1"]; #line 13
进入
if [ -s "p1" ]; #line 13
注意空格.
这篇关于Bash脚本缺少“]"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文