Bash 脚本缺少“]" [英] Bash scripting missing ']'

查看:31
本文介绍了Bash 脚本缺少“]"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到一个错误 ./test.sh: line 13: [: missing `]' in the file 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆