Solved

shell script syntax

Posted on 2006-07-04
6
566 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this post we will learn different types of Android Layout and some basics of an Android App.
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 video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

752 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