Sunday, March 30, 2008

bash quicksand 1: whitespaces in variable assignment

bash is a very powerful scripting language. However, there is a learning curve that frustrates many.

In a series of bash quicksand blog entries, I hope to post some warning signs about what to avoid.
I want to write them down because after one gets used to bash syntax, one tends to forget about the initial hurdles. Hopefully, no late comers will be trapped in bash quicksand.

Let's begin.

Say you want to assign the text string myvalue to some variable myvariable. What is more simple than that?

$ myvariable = myvalue
bash: myvariable: command not found
$


Oops. And you vowed that it worked before.

What transpired was that bash attempts to execute the command myvariable with the arguments = and myvalue.

Proper syntax requires no whitespace before and after the equal sign:
$ myvariable=myvalue
$ echo $myvariable
myvalue
$

1 comment:

Term Papers said...

I have been visiting various blogs for my term papers writing research. I have found your blog to be quite useful. Keep updating your blog with valuable information... Regards