-
-
Save CryptoFewka/d8b54a34e4385a3b9be10a67eb71c88f to your computer and use it in GitHub Desktop.
bash script to convert more text to morse code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
#set -x | |
####################################### | |
declare -A morse | |
morse[0]='- - - - -' | |
morse[1]='. - - - -' | |
morse[2]='. . - - -' | |
morse[3]='. . . - -' | |
morse[4]='. . . . -' | |
morse[5]='. . . . .' | |
morse[6]='- . . . .' | |
morse[7]='- - . . .' | |
morse[8]='- - - . .' | |
morse[9]='- - - - .' | |
morse[A]='. -' | |
morse[B]='- . . .' | |
morse[C]='- . - .' | |
morse[D]='- . .' | |
morse[E]='.' | |
morse[F]='. . - .' | |
morse[G]='- - .' | |
morse[H]='. . . .' | |
morse[I]='. .' | |
morse[J]='. - - -' | |
morse[K]='- . -' | |
morse[L]='. - . .' | |
morse[M]='- -' | |
morse[N]='- .' | |
morse[O]='- - -' | |
morse[P]='. - - .' | |
morse[Q]='- - . -' | |
morse[R]='. - .' | |
morse[S]='. . .' | |
morse[T]='-' | |
morse[U]='. . -' | |
morse[V]='. . . -' | |
morse[W]='. - -' | |
morse[X]='- . . -' | |
morse[Y]='- . - -' | |
morse[Z]='- - . .' | |
morse[.]='. - . - . -' | |
morse[,]='- - . . - -' | |
morse[;]='- . - . - .' | |
morse[:]='- - - . . .' | |
morse[-]='- . . . . -' | |
morse[/]='- . . - .' | |
morse[\']='. - - - - .' | |
morse[\"]='. - . . - .' | |
####################################### | |
while read -rN1 c; do | |
c=${c^} | |
if [[ $c == $'\n' ]]; then | |
printf '\n' | |
elif [[ $c == ' ' ]]; then | |
printf ' ' | |
else | |
printf '%s ' "${morse[$c]}" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How can i do for show only morse?
like:
.... . .-.. .-.. ---
instead of:
H.... e. l.-.. l.-.. o---
Thank you for all!