Move under www to ease rsync
This commit is contained in:
36
www/eps/hpr2709/hpr2709_bash16_ex1.sh
Executable file
36
www/eps/hpr2709/hpr2709_bash16_ex1.sh
Executable file
@@ -0,0 +1,36 @@
|
||||
#!/bin/bash
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Example 1 for Bash Tips show 16: the difference between '*' and '@' as array
|
||||
# subscripts
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#
|
||||
# Initialise an array
|
||||
#
|
||||
declare -a words
|
||||
|
||||
#
|
||||
# Populate the array. Omit capitalised words and the weird possessives.
|
||||
# [Note: there are better ways of populating arrays as we'll see in a later
|
||||
# show]
|
||||
#
|
||||
for word in $(grep -E -v "(^[A-Z]|'s$)" /usr/share/dict/words | shuf -n 5); do
|
||||
words+=( "$word" )
|
||||
done
|
||||
|
||||
#
|
||||
# Report the array using '*' as the index
|
||||
#
|
||||
echo 'Using "${words[*]}"'
|
||||
for word in "${words[*]}"; do
|
||||
echo "$word"
|
||||
done
|
||||
|
||||
#
|
||||
# Report the array using '@' as the index
|
||||
#
|
||||
echo 'Using "${words[@]}"'
|
||||
for word in "${words[@]}"; do
|
||||
echo "$word"
|
||||
done
|
||||
Reference in New Issue
Block a user