Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


shell script syntax

Posted on 2006-07-04
Medium Priority
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"
     # 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
Question by:screwdriver
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
LVL 24

Expert Comment

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

Author Comment

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

Accepted Solution

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...
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

LVL 48

Expert Comment

ID: 17046200

-ne is for comparing integers.
LVL 24

Expert Comment

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

Author Comment

ID: 17048535
Thank you guys, it works now.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

705 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