Solved acronym in Bash
This commit is contained in:
13
bash/acronym/acronym.sh
Normal file
13
bash/acronym/acronym.sh
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# replaces any character that is not alphanumeric ([:alnum:]),
|
||||
# a blank space ([:blank:]), or a single quote (') with a space character
|
||||
# and convert to uppercase
|
||||
phrase=$(echo "$1" | tr -c "[:alnum:][:blank:]'" " " | tr "[:lower:]" "[:upper:]")
|
||||
|
||||
# appends the first character of each word to $acronym
|
||||
for word in $phrase; do
|
||||
acronym+=$(echo "${word:0:1}")
|
||||
done
|
||||
|
||||
echo "$acronym"
|
||||
Reference in New Issue
Block a user