Sunday, 15 May 2011

little on bash scripting

Linux Bash Scripting


Simple Array
_________________________________________
$ name=("chantu"  "bhantu"  "santa"  Bhanta)
OR
$ name=(chantu bhantu santa bhanta)
_________________________________________

Iterating over an Simple Array

_________________________________________
$for a in ${name[*]}
do
echo $a;
done
_________________________________________

Associative Array 
NOTE: Only in bash > v4.x
_________________________________________
$ declare -A name
$ name=(["father"]="bhantu"  ["brother"]="chantu")
_________________________________________
iterating over an associative array

_________________________________________
$ for relation in ${!name[*]}
do 
echo "Relation $relation in ${name["$relation"]}"
done
_________________________________________


Evaluating an expression
$expr 2 + 2 
NOTE: SPACES BETWEEN OPERATOR AND OPERANDS

No comments:

Post a Comment