Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

UNIX Using the bash shell, create an English to Morse Code translator. The scrip

ID: 3838986 • Letter: U

Question

UNIX

Using the bash shell, create an English to Morse Code translator. The script will take a string as it's only parameter. The script will handle capital letters, numbers and space only. The script will use an associative array to look up the English letter and find its matching Morse Code. Between each code will be a ",SP,", and at the end of the line an EOT. If there is a space at the beginning "SP," or end ",SP" of the line there will only be one comma needed.

Morse Code

1. The length of a dot is one unit.

2. A dash is three units.

3. The space between parts of the same letter is one unity.

4. The space between letters is three units.

5. The space between words is seven units.

... 0 T III. LI III :::::IIIII UVWXYZ 1234567890 -..-:: I . 1-1 ·LI LI: ABCDEFGH-JK L M N O P QRST

Explanation / Answer

morse=$1
for (( k = 0; $k < ${#morse}; k = $k +1 ));
do
echo ${morse:$k:1}
done

declare -A morse
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[1]=".;-;-;-;-"
morse[2]=".;.;-;-;-"
morse[3]=".;.;.;-;-"
morse[4]=".;.;.;.;-"
morse[5]=".;.;.;.;."
morse[6]="-;.;.;.;."
morse[7]="-;-;.;.;."
morse[8]="-;-;-;.;."
morse[9]="-;-;-;-;."
morse[0]="-;-;-;-;-"