Bash Missing Scripts ']'

I get an error message. /test.sh: line 13: [: missing `] in the test.sh file I tried using brackets and other parameters, such as -a or by checking the size of the p1 file, but the error always exists, and the else statement always runs regardless entered input. I even tried to remove; on line 13, but that 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 

I am new to bash scripting. So if there is a stupid mistake, please excuse me.

+62
scripting bash
Apr 13 '13 at 21:18
source share
5 answers

Change

 if [ -s "p1"]; #line 13 

at

 if [ -s "p1" ]; #line 13 

mark a space.

+169
Apr 13 '13 at 21:20
source share

I got this error while trying to use the && operator inside separate brackets, for example [ ... && ... ] . I had to switch to [[ ... && ... ]] .

+22
Jan 18 '17 at 21:05
source share

You are missing a space after "p1" :

 if [ -s "p1" ]; 
+8
Apr 13 '13 at 21:20
source share

add a space before the closing bracket

+6
Apr 13 '13 at 21:20
source share

if [-s "p1"];

follow the space: P

0
Sep 24 '19 at 11:45
source share



All Articles