Solved

shell script syntax

Posted on 2006-07-04
6
562 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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.

864 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now