LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-13-2012, 04:32 AM   #1
Monalisa Chan
LQ Newbie
 
Registered: Nov 2012
Posts: 8

Rep: Reputation: Disabled
I would like to know what's wrong my scripts.Please help me!


Student name=
Student admission=
./choice4.sh: line5: [: missing `]'
Exception :YES
Details:
=========================================

In script,
line1 #!/ usr/bin/bash
line2 echo "Student name= "
line3 echo "Student admission= "
line4 password = cat /etc/default/passwd | grep MAXWEEKS
line5 if [$password == "2" ]
line6then
line7 echo "Exception: NO"
line8 echo "Details:"
line9 echo "=========="
line10 cat /etc/default/passwd | grep MAXWEEKS
line11else
line12 echo "Exception :YES"
line13 echo "Details: "
line14 echo "============"
line15 cat /etc/default/passwd
line16 fi
 
Old 11-13-2012, 04:36 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
it looks like you've not transcribed that quite right, but "[" is actually a *program* (well, a link to the /bin/test program), you need to ensure that [ and ] have whitespace around them, like any other option / program name.

note... [ is not great. If you're learning bash, use [[ instead, as it's much nicer to use (and is NOT a program, it's actual bash syntax)
 
Old 11-13-2012, 04:36 AM   #3
dragonix
Member
 
Registered: Nov 2012
Location: Belgium
Distribution: Ubuntu 12.04
Posts: 69
Blog Entries: 6

Rep: Reputation: 1
Quote:
Originally Posted by Monalisa Chan View Post
Student name=
Student admission=
./choice4.sh: line5: [: missing `]'
Exception :YES
Details:
=========================================

In script,
line1 #!/ usr/bin/bash
line2 echo "Student name= "
line3 echo "Student admission= "
line4 password = cat /etc/default/passwd | grep MAXWEEKS
line5 if [$password == "2" ]
line6then
line7 echo "Exception: NO"
line8 echo "Details:"
line9 echo "=========="
line10 cat /etc/default/passwd | grep MAXWEEKS
line11else
line12 echo "Exception :YES"
line13 echo "Details: "
line14 echo "============"
line15 cat /etc/default/passwd
line16 fi
try using this
Code:
line5 if [[ $password == "2" ]]
So double [[ and a space between the brackets and values

EDIT
See acid_kewpie's post
 
Old 11-13-2012, 04:37 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
Quote:
Originally Posted by dragonix View Post
try using this
Code:
line5 if [[ $password == "2" ]]
So double [[ and a space between the brackets and values
well note that [[ will do proper tokenisation of the string, so there's no need for the "'s in there. unlike [
 
Old 11-13-2012, 04:41 AM   #5
dragonix
Member
 
Registered: Nov 2012
Location: Belgium
Distribution: Ubuntu 12.04
Posts: 69
Blog Entries: 6

Rep: Reputation: 1
Quote:
Originally Posted by acid_kewpie View Post
well note that [[ will do proper tokenisation of the string, so there's no need for the "'s in there. unlike [
So, if I get it right, you mean it like

Code:
if [[ $password == 2 ]]
 
Old 11-13-2012, 04:45 AM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
Quote:
Originally Posted by dragonix View Post
So, if I get it right, you mean it like

Code:
if [[ $password == 2 ]]
Yeah, as above it's pure bash, so is processed purely within bash itself instead of being passed through to separate binaries as arbitrary command parameters.
 
Old 11-13-2012, 04:46 AM   #7
Monalisa Chan
LQ Newbie
 
Registered: Nov 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
I put double [[ . Now I can fix the error. Thanks a lot =)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Wrong disk free space (VERY wrong) macrojd Linux - Server 12 05-17-2009 03:14 AM
rsync uses wrong directory, has wrong size but right file count? brianpbarnes Linux - Software 1 02-23-2009 06:48 PM
Fortran - G95 - Wrong Syntax or wrong compiler settings laucian Programming 1 03-21-2008 11:18 AM
What is wrong with reiserfs? wrong free space mesh2005 Linux - General 1 05-03-2007 08:21 AM
VPN: Debian Scripts -> Mandriva 2006 Scripts Undefined Mandriva 0 11-30-2005 01:10 PM


All times are GMT -5. The time now is 04:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration