From 9c227f5a0026ce41755f8343c5050c4fbee81c65 Mon Sep 17 00:00:00 2001 From: Ed Braaten Date: Wed, 22 Apr 2015 07:40:55 -0700 Subject: [PATCH] Added animals array example to hello.sh bash script. --- bash/hello.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bash/hello.sh b/bash/hello.sh index 0869db8..032468d 100755 --- a/bash/hello.sh +++ b/bash/hello.sh @@ -3,6 +3,7 @@ # Sample Hello World! bash script... # +declare -a animals=("camel" "llama" "owl") declare -A FRUIT_COLOR 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` 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) +echo ""; echo "Value of fruit_color hash:" declare -A sorted_fruit for fruit in "${!FRUIT_COLOR[@]}"; do echo "$fruit = ${FRUIT_COLOR["$fruit"]}";