Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to run a small script - test - on ubuntu box.

It is as follows:

var1 = bash

var2 = /home/test/directory

<some more variable assignments and then program operations here>

Now every time I run it, then it throws errors:


/opt/test: line 1: var1: command not found
/opt/test: line 3: var2: command not found
more similar errors

Can someone help me understand what is wrong in this script?

Many thanks.

share|improve this question
Your script really should start with something like #!/bin/sh, #!/bin/bash, or whatever shell you are using. – Zoredache Jul 10 '12 at 21:35
It does not use /bin/sh or /bin/bash. It assigns some variables and later uses python to execute scripts that refer to these variables. It was working fine 3 weeks or so earlier n then I updated the kernel. not sure what changed but this was working fine. – newcoder Jul 10 '12 at 21:53
You cannot have a script without one of those. If you haven't explicitly identified the shell using #! you are using then the shell you are currently running is being used. – Zoredache Jul 10 '12 at 22:06

First, You need to escape the first string (the second string as a path DOES NOT require escaping) var1="Variable" Second, There can't be any spaces in the syntax. var2=/this/is/path/to/foo

share|improve this answer
Sorry, in my post, I meant, var1 = bash. Now, when I do: var1=bash var2=/opt/test, then I get this error: /opt/test: line 3: var2: command not found. – newcoder Jul 10 '12 at 21:07
Are you separating the variables with newlines? Otherwise your script should read: #!/bin/bash var1="bash" var2=/path/to/foo – iambryan Jul 10 '12 at 21:34
Update: Now I made var2=/opt/test. So the error is gone. But on the next line, I have var3=$var2/another_file. Now it gives error saying: var3: command not found – newcoder Jul 10 '12 at 21:48
Actually, this script was working fine earlier. Then I updated the kernel n now it has gone down. No idea what changed. – newcoder Jul 10 '12 at 21:51
Are you able to post the script? – iambryan Jul 10 '12 at 21:55

With out having the whole picture it's hard see what your trying to do, but it looks like your using a shell script to assign some environment variables before calling python. You need to put "#!/bin/bash" (or what ever shell you want) at the top of your file as others mentioned. Running "/bin/bash scriptname" may also work, but no guarantees.

You may want to look at some of the shell programming tutorials out there (Google is your friend) to get pointing in the right direction.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.