Added animals array example to hello.sh bash script.
This commit is contained in:
parent
1093f0ba9e
commit
9c227f5a00
1 changed files with 14 additions and 0 deletions
|
|
@ -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"]}";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue