LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 09-13-2010, 03:55 AM   #1
mahmoodn
Member
 
Registered: May 2010
Posts: 427

Rep: Reputation: 16
Question sh: [[: not found


I have this line in my in a .sh file:
Code:
#!/bin/bash
...
  env PATH=$SOMETHING:$PATH $MUNGE $CKPT/$TYPE_N > $CKPT_BASE/$TYPE_N.munge_output
  echo " "
  if [ $? -ne 0 ]; then
    echo "Munge failed!"
    exit -1
  fi
fi

if [[ $TYPE == "some_type" ]] ; then
	...
But I see this message in the output:
Code:
sh: [[: not found
If I comment the bold line (env command), then there is no problem.

What should I do?
 
Old 09-13-2010, 05:49 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

The posted code snippet doesn't tell us what it is you are trying to do. $TYPE isn't mentioned, just the check is shown. $TYPE_N is mentioned, but not checked.

I do see one thing that probably doesn't work as expected:
Code:
env PATH=$SOMETHING:$PATH ......
echo " "
if [ $? -ne 0 ]; then ....
The if statement checks if the previous command was executed successfully. The previous command being echo " ", not the env .... command!

The second if command (if [[ $TYPE == "some_type" ]] ; then) could fail if $TYPE is empty. If $TYPE is empty the command will look like this:
if [[ == "some_type" ]] ; then, which is syntactically incorrect and bash will complain.

You can solve this by putting double quotes around the variable: if [[ "$TYPE" == "some_type" ]] ; then.

Hope this helps.
 
Old 09-13-2010, 06:16 AM   #3
mahmoodn
Member
 
Registered: May 2010
Posts: 427

Original Poster
Rep: Reputation: 16
Code:
#!/bin/bash
...
  env PATH=$SOMETHING:$PATH $MUNGE $CKPT/$TYPE_N > $CKPT_BASE/$TYPE_N.munge_output

  if [ $? -ne 0 ]; then
    echo "Munge failed!"
    exit -1
  fi
  echo "TYPE=$TYPE"
  echo "TYPE_N=$TYPE_N"
  echo "CKPT_BASE=$CKPT_BASE"
  echo "MUNGE=$MUNGE"
fi

if [[ $TYPE == "some_type" ]] ; then
	...
These are the variables in the output (all of the other variables are set correctly):
Code:
TYPE=some_type
TYPE_N=flex_001
CKPT_BASE=/home/mahmood/checkpoints
MUNGE=/home/mahmood/scripts/munge.py
As I said if I remove "env" command, there is no problem so the error must be related to that command.

can you please explain what does this mean?
Code:
env PATH=$SOMETHING:$PATH $MUNGE $CKPT/$TYPE_N > $CKPT_BASE/$TYPE_N.munge_output
 
Old 09-13-2010, 06:43 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,
Quote:
These are the variables in the output (all of the other variables are set correctly):
Code:
TYPE=some_type
TYPE_N=flex_001
CKPT_BASE=/home/mahmood/checkpoints
MUNGE=/home/mahmood/scripts/munge.py
As I said if I remove "env" command, there is no problem so the error must be related to that command.
Not necessarily. If bash isn't able to figure out how to parse the code it is given, the error can appear on a seemingly random place.

I do agree in this case that the env command is probably the culprit, see my next comment.

Quote:
can you please explain what does this mean?
Code:
env PATH=$SOMETHING:$PATH $MUNGE $CKPT/$TYPE_N > $CKPT_BASE/$TYPE_N.munge_output
This PATH=$SOMETHING:$PATH will prepend the content of $SOMETHING to your PATH (whatever $SOMETHING may be).

This part $MUNGE $CKPT/$TYPE_N doesn't make too much sense, it (the env command) will try to execute /home/mahmood/scripts/munge.py and $CKPT/flex_001 ($CKPT isn't mentioned in your code snippet).

All output created by the env command is redirected to /home/mahmood/checkpoints/flex_001.

Without knowing what you are trying to accomplish, the env ..... statement doesn't make too much sense. The environment is not meant to execute commands, it holds variables that can be set and unset which are used by other programs.

Hope this helps.
 
Old 09-13-2010, 06:54 AM   #5
mahmoodn
Member
 
Registered: May 2010
Posts: 427

Original Poster
Rep: Reputation: 16
Code:
env PATH=$SOMETHING:$PATH $MUNGE $CKPT/$TYPE_N > $CKPT_BASE/$TYPE_N.munge_output
if [ $? -ne 0 ]; then
    echo "Munge failed!"
    exit -1
I know that $? shows the return code of the previous command, but what is the return code of env command? what does it mean when env returns 0 or anything else?
 
Old 09-13-2010, 07:06 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Exit code 0 means that the command was executed successfully. In general any other number means that the command did not run successfully. You do need to look at the man page for that command for their specific meaning, grep for example can throw an exit code of 1, which means that no hit was found (which isn't an error).

If you want to know the specific exit status of the env command try: echo $1 ; exit (in between the env .... command and the if [$? -ne 0 ]; part.

BTW: an exit code is, too my knowledge, always positive. 0 being OK, none zero being not OK (or special). This: exit -1 is incorrect, that should be exit 1 (positive number, one or higher).

Hope this helps.
 
Old 09-13-2010, 08:16 AM   #7
mahmoodn
Member
 
Registered: May 2010
Posts: 427

Original Poster
Rep: Reputation: 16
Quote:
Not necessarily. If bash isn't able to figure out how to parse the code it is given, the error can appear on a seemingly random place.
That makes it very hard to debug....
 
Old 09-13-2010, 08:31 AM   #8
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,
Quote:
Originally Posted by mahmoodn View Post
That makes it very hard to debug....
It does make things more interesting, true

Most of the time it is a forgotten opening/closing X. X could be a (double) quote, bracket, brace etc. Syntax highlighting helps in catching these typo's/mistakes.

You can also create stop points yourself. Like the one I posted in post #6 (the echo $1 ; exit).

You can also use the set -x option (immediately below the #!/bin/bash line), it is meant for debugging.

Hope this helps.
 
Old 09-13-2010, 08:47 AM   #9
mahmoodn
Member
 
Registered: May 2010
Posts: 427

Original Poster
Rep: Reputation: 16
That "set -x" was useful. I have attached the script file (since I couldn't upload *.sh file, I renamed it to *.txt!!) and the log file which shows the debug information. The error is at line 115 of log.txt.

I will be thankful if you have a look at it.
Thanks,

Last edited by mahmoodn; 09-14-2010 at 07:15 AM.
 
Old 09-13-2010, 08:53 AM   #10
djsmiley2k
Member
 
Registered: Feb 2005
Location: Coventry, UK
Distribution: Home: Gentoo x86/amd64, Debian ppc. Work: Ubuntu, SuSe, CentOS
Posts: 343
Blog Entries: 1

Rep: Reputation: 72
Your missing aload of colons ':' in the env and instead have spaces.

Code:
/home/mahmood/flexus-4.0/scripts/munge-checkpoint.py /home/mahmood/flexus-4.0/checkpoint
Kind of hard to highlight really, but you can see there is a space, instead of :, there is others too.

OR your trying to run a command on the env line... which isn't going to work as others pointed out already.
 
Old 09-13-2010, 08:59 AM   #11
mahmoodn
Member
 
Registered: May 2010
Posts: 427

Original Poster
Rep: Reputation: 16
Yes you are right. The reason was
Code:
env PATH=$SOMETHING:$PATH $MUNGE $CKPT/$TYPE_N > $CKPT_BASE/$TYPE_N.munge_output
The spaces were there. So I fixed it with
Code:
env PATH=$SOMETHING:$PATH:$MUNGE:$CKPT/$TYPE_N > $CKPT_BASE/$TYPE_N.munge_output
And it is now fine.

Thanks druuna and djsmiley2k
 
Old 09-13-2010, 09:03 AM   #12
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
You're welcome
 
Old 09-13-2010, 09:12 AM   #13
djsmiley2k
Member
 
Registered: Feb 2005
Location: Coventry, UK
Distribution: Home: Gentoo x86/amd64, Debian ppc. Work: Ubuntu, SuSe, CentOS
Posts: 343
Blog Entries: 1

Rep: Reputation: 72
\o/ my bash skills are improving; good times ^_^
 
  


Reply



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
Fedora Core 6 boot No medium found No volume groups found awadhut Linux - Hardware 1 02-22-2007 01:15 AM
INIT NOT FOUND + HDA(x) NOT FOUND fred99 Linux - Software 1 02-25-2005 02:10 PM
CDROM found/not found SUSE 9.2 dirdej SUSE / openSUSE 4 01-14-2005 11:58 PM
gcc vs. g++ -> iostream lib found vs. not found CooManChu Linux - General 1 12-11-2004 09:20 AM
PDC 20276 - Promise Fasttrack 133 found but still not found.. FransE Linux - Hardware 3 02-16-2004 07:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 11:00 AM.

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
Open Source Consulting | Domain Registration