Solved

shell script syntax

Posted on 2006-07-04
6
564 Views
Last Modified: 2013-12-26
I've started learning the shell script and I got this error when executing the following script.  Need help solving this.

the error I got:
./testsc: line 11: [: missing `]'
./testsc: line 11: [: missing `]'

and line 11 is:
while [`head -1 ./temp` -neq 'Finished']   # check if the first line is not "Finished"
  do
     # grab four lines and save it under file result
     head -4 ./temp >> result

     # remove the first 12 lines. The next meaningful data is at line 13
     sed '1,12d' ./temp > ./temp
  done
0
Comment
Question by:screwdriver
  • 3
  • 2
6 Comments
 
LVL 24

Expert Comment

by:slyong
ID: 17040577
while [ `head -1 ./temp` -neq 'Finished' ]   # check if the first line is not "Finished"
          ^                                             ^
put space after [ and before ]
0
 

Author Comment

by:screwdriver
ID: 17044477
got different error now:
./testsc: line 11: [: -neq: binary operator expected
./testsc: line 11: [: too many arguments
0
 
LVL 24

Accepted Solution

by:
slyong earned 50 total points
ID: 17045605
while [ `head -1 ./temp` != 'Finished' ]   # check if the first line is not "Finished"

                                     ^^ when comparing string use !=, ! -eq is for comparing integer...
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 48

Expert Comment

by:Tintin
ID: 17046200
slyong

-ne is for comparing integers.
0
 
LVL 24

Expert Comment

by:slyong
ID: 17046213
Thank Tintin.. my bad.. I always negate the -eq using !.
0
 

Author Comment

by:screwdriver
ID: 17048535
Thank you guys, it works now.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question