Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash scripting missing ']' [closed]

Tags:

bash

scripting

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 

I am new to bash scripting.So if there is any silly mistake please excuse me.

like image 589
quick- Avatar asked Apr 13 '13 21:04

quick-


1 Answers

Change

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

into

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

note the space.

like image 127
Fredrik Pihl Avatar answered Sep 29 '22 11:09

Fredrik Pihl