Move under www to ease rsync
This commit is contained in:
32
www/eps/hpr2729/hpr2729_bash18_ex2.sh
Executable file
32
www/eps/hpr2729/hpr2729_bash18_ex2.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Example 2 for Bash Tips show 18: transforming words in a string, second
|
||||
# simpler method that depends on the '-v' operator
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#
|
||||
# What we'll work on and where we'll store the transformed version
|
||||
#
|
||||
phrase='Now is the time for all good men to come to the aid of the party'
|
||||
newphrase=
|
||||
|
||||
#
|
||||
# How to transform words in the phrase
|
||||
#
|
||||
declare -A transform=([good]='bad' [men]='people' [aid]='assistance'
|
||||
[party]='Community')
|
||||
|
||||
#
|
||||
# Go word by word; if an element with the word as a key exists in the
|
||||
# 'transform' array replace the word by what's there.
|
||||
#
|
||||
for word in $phrase; do
|
||||
if [[ -v transform[$word] ]]; then
|
||||
word=${transform[$word]}
|
||||
fi
|
||||
newphrase+="$word "
|
||||
done
|
||||
echo "$newphrase"
|
||||
|
||||
exit
|
||||
Reference in New Issue
Block a user