Solved acronym in Bash

This commit is contained in:
2023-04-25 19:23:26 +02:00
parent 76c2f81d48
commit 0a54d06454
7 changed files with 908 additions and 0 deletions

13
bash/acronym/acronym.sh Normal file
View 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"