Monday, January 09, 2006

Getting Started with Shell

I am finally tired of wasting so much time on fixing trival shell errors and decided to spend an hour or two to kill the basics of it.

1. Formatting Issues - Spaces do matter.
I haven't found any summaries online about this, but just from personal experiences, first, if you are assigning values to variables, you need to elimate all spaces around the equal sign. E.g. You have to write something like
var="string"
instead of
var = "string" or var= "string" or var ="string".

On the contrary, spaces are necessary to separate other operators. When using if [], you have to use space to separate [ or ] from the operator it uses inside. E.g. you have to write
if [ -z $string ]; then ... ; fi
instead of
if [-z $string ]; string ... ; fi etc.

2. Just as some convenient links, here are all the comparison operators
http://www.tldp.org/LDP/abs/html/comparison-ops.html
and file operators
http://www.tldp.org/LDP/abs/html/fto.html


And for more information here are some quick starts and references http://quong.best.vwh.net/shellin20/; http://www.tldp.org/LDP/abs/html/ and http://linux.org.mt/article/terminal

3. To test whether a variable is a string or not in shell, there is no straightforward way to do it, the closest i found is

if [ -z `echo $var tr -d "[:digit:]"` ]; then ... ; fi

0 Comments:

Post a Comment

<< Home