Added animals array example to hello.sh bash script.

This commit is contained in:
Ed Braaten 2015-04-22 07:40:55 -07:00
parent 1093f0ba9e
commit 9c227f5a00

View file

@ -3,6 +3,7 @@
# Sample Hello World! bash script... # Sample Hello World! bash script...
# #
declare -a animals=("camel" "llama" "owl")
declare -A FRUIT_COLOR declare -A FRUIT_COLOR
FRUIT_COLOR=( ["apple"]="red" ["banana"]="yellow") FRUIT_COLOR=( ["apple"]="red" ["banana"]="yellow")
@ -19,7 +20,20 @@ echo "Command line args: $*"
SOCKETCOUNT=`cat /proc/cpuinfo | grep 'physical id' | sort | uniq | wc -l` SOCKETCOUNT=`cat /proc/cpuinfo | grep 'physical id' | sort | uniq | wc -l`
echo "CPU socket count: $SOCKETCOUNT" echo "CPU socket count: $SOCKETCOUNT"
# print out our animals array in reverse-sorted order
echo ""; echo "Value of animals array:"
for i in `(for animal in "${animals[@]}"; do echo "$animal"; done | sort --reverse)`
do
echo "item = $i"
if [[ "$i" == "${animals[0]}" ]]; then
echo " Condition is TRUE, $i == ${animals[0]}"
else
echo " Condition is FALSE, $i != ${animals[0]}"
fi
done
# print out our FRUIT_COLOR associative array (key/value pairs) # print out our FRUIT_COLOR associative array (key/value pairs)
echo ""; echo "Value of fruit_color hash:"
declare -A sorted_fruit declare -A sorted_fruit
for fruit in "${!FRUIT_COLOR[@]}"; do for fruit in "${!FRUIT_COLOR[@]}"; do
echo "$fruit = ${FRUIT_COLOR["$fruit"]}"; echo "$fruit = ${FRUIT_COLOR["$fruit"]}";