Continuing my quest to learn BASH, Bourne, Awk, Grep, etc. on my own through the use of a few books. I've come to an exercise that has me absolutely stumped.
The specifics:
- Using ONLY BASH scripting commands (not sed, awk, etc.), write a script to convert a string on the command line to Morse code. The script will handle only capital letters and numbers
- It will convert the string given on the command line as in the
following example:
$ ./morse.bash �CAT IN�
-.-.,.-,-,SP,..,-.,EOT (SP is used for a space, and EOT for end of transmission). - An associative array is to be used for the �lookup table� to do the
conversion from a character to Morse Code.
This is my time using an associative array, so this exercise has me stumped. Any help, guidance, suggestions are greatly appreciated. Here's what I have so far:
morse=$1
for (( i = 0; $i < ${#morse}; i = $i +1 ));
do
echo ${morse:$i:1}
done
declare -A morse #Declare associative array
morse[A]=".;-"
morse="-;.;.;."
morse[C]="-;.;-;."
morse[D]="-;.;."
morse[E]="."
morse[F]=".;.;-;."
morse[G]="-;-;."
morse[H]=".;.;.;."
morse=".;."
morse[J]=".;-;-;-"
morse[K]="-;.;-"
morse[L]=".;-;.;."
morse[M]="-;-"
morse[N]="-;."
morse[O]="-;-;-"
morse[P]=".;-;-;."
morse[Q]="-;-;.;-"
morse[R]="-;-;.;-"
morse=".;.;."
morse[T]="-"
morse=".;.;-"
morse[V]=".;.;.;-"
morse[W]=".;-;-"
morse[X]="-;.;.;-"
morse[Y]="-;.;-;-"
morse[Z]="-;-;.;."
morse[1]=".;-;-;-;-"
morse[2]=".;.;-;-;-"
morse[3]=".;.;.;-;-"
morse[4]=".;.;.;.;-"
morse[5]=".;.;.;.;."
morse[6]="-;.;.;.;."
morse[7]="-;-;.;.;."
morse[8]="-;-;-;.;."
morse[9]="-;-;-;-;."
morse[0]="-;-;-;-;-"



