Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

shell script syntax

Posted on 2006-07-04
6
Medium Priority
?
580 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 200 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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 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.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…

926 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