小编qui*_*ck-的帖子

Bash脚本缺少']'

我在文件test.sh中收到错误./test.sh:line 13:[:missing`]'我尝试使用括号和其他选项(如-a)或通过检查文件p1的大小但错误是总是在那里,而且无论给出什么输入,都会执行else语句.我甚至尝试删除; 在第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
Run Code Online (Sandbox Code Playgroud)

我是bash脚本的新手.如果有任何愚蠢的错误,请原谅.

bash scripting

62
推荐指数
4
解决办法
8万
查看次数

标签 统计

bash ×1

scripting ×1