26 lines
565 B
Bash
26 lines
565 B
Bash
|
|
#!/bin/bash
|
||
|
|
|
||
|
|
#-------------------------------------------------------------------------------
|
||
|
|
# Example 2 for Bash Tips show 15 - you can also use a 'for' loop to load an
|
||
|
|
# array
|
||
|
|
#-------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
#
|
||
|
|
# Initialise an array
|
||
|
|
#
|
||
|
|
items=()
|
||
|
|
|
||
|
|
#
|
||
|
|
# Populate the array with random words
|
||
|
|
#
|
||
|
|
for word in $(grep -E -v "'s$" /usr/share/dict/words | shuf -n 5); do
|
||
|
|
items+=( "$word" )
|
||
|
|
done
|
||
|
|
|
||
|
|
#
|
||
|
|
# Print the array with word numbers
|
||
|
|
#
|
||
|
|
for ((i = 0, j = 1; i < ${#items[@]}; i++, j++)); do
|
||
|
|
echo "$j: ${items[$i]}"
|
||
|
|
done
|