Skip to content

Instantly share code, notes, and snippets.

@CryptoFewka
Forked from jessebutryn/morse.sh
Last active November 14, 2022 19:23
Show Gist options
  • Save CryptoFewka/d8b54a34e4385a3b9be10a67eb71c88f to your computer and use it in GitHub Desktop.
Save CryptoFewka/d8b54a34e4385a3b9be10a67eb71c88f to your computer and use it in GitHub Desktop.
bash script to convert more text to morse code
#!/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
@scr-k
Copy link

scr-k commented Nov 14, 2022

How can i do for show only morse?
like:
.... . .-.. .-.. ---
instead of:
H.... e. l.-.. l.-.. o---

Thank you for all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment