I am new in linux. Trying to run sh file which connects the server over FTP or VSFTPD and get some files. Here is my Script

USER = 'user'
PASS = 'password'

FILE = 'path/filename.txt'

quote USER $USER
quote PASS $PASS
get $FILE

exit 0

When i try to run this file: sh file.sh it throws error:

file.sh: 3: file.sh: HOST: not found
file.sh: 4: file.sh: USER: not found
file.sh: 5: file.sh: PASS: not found
file.sh: 7: file.sh: FILE: not found
Not Connected.
Not Connected.
Not Connected.

Remove Spaces between variable and its value.


Assignment in bash scripts cannot have spaces around the =

For more understand = also is compare operator. see this example:

if [ "$a" = "$b" ]

enter image description here Note the whitespace framing the =. In this case we are comparing "$a" and "$b".

if [ "$a"="$b" ] is not equivalent to the above.

Testing with example:

kasiay@kasiyaPC~:$ a=2
kasiay@kasiyaPC~:$ b=3

Then we run if [ "$a" = "$b" ]; then echo "equal"; else echo "not equal"; fi, the result will "not equal" and it's true result.

But if we run if [ "$a"="$b" ]; then echo "equal"; else echo "not equal"; fi, the result will "equal" and it's wrong result!!

Why in this case we are wrong result?

When we are using if [ "$a"="$b" ], it parsing as if [ A_TOKEN ], then in this case the if condition always return true result. for example:

if [ "$a"="$b" ]; then    echo "TRUE"; fi
#result is TRUE

if [ 2=3 ]; then    echo "TRUE"; fi
#result is TRUE    

if [ anything ]; then    echo "TRUE"; fi
#result is TRUE

And finally when you are using USER = 'user' (I don't know which section parse this), then you are getting "not found" . and Why is "not found"?? since the parser looking for value of USER variable to compare with 'user' value. and it's "not found" right?

| improve this answer | |
  • I really have no idea, but WHY? – Sarz Sep 30 '14 at 6:06
  • Can you help me in one more thing, at what level of path user logged in – Sarz Sep 30 '14 at 6:13
  • @Sarz you can add pwd command to find out path level. Add it on the new line between quote PASS $PASS and get $FILE – c0rp Sep 30 '14 at 6:28
  • 1
    Also, another note for your shell script, Sarz. It is generally considered bad practice to use all upper case for variable names since they may clash with Bash builtin variables or other environment variables. This script actually exemplifies this. Open a new terminal and don't run your script. Then, type echo $USER. Your username will be printed to the terminal. So, by setting $USER in your script, you are effectively overwriting this already-defined variable which may lead to unexpected results in some cases! – Chuck R Nov 1 '14 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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