Posts

Showing posts with the label beep

morse script 2

I'll copy in the actual code below later, but I can't right now because I'm using ssh to a headless machine at work. I gave up on reading the letters from a separate text file - seemed like too much overhead for what I wanted to do. Instead I've found out how to create an associative array within my bash script. This'll let me pass the user input variable as a key that will return the binary value. SO, I have the following: #!/bin/bash # declare array and assign values to each letter # make sure no spaced between array var, = and ( declare -A morseCode_arr=( [a]=01 [b]=1000 [c]=1010 [d]=100 [e]=0 [f]=0010 [g]=110 [h]=0000 [i]=00 [j]=0111 [k]=101 [l]=0100 [m]=11 [n]=10 [o]=111 [p]=0110 [q]=1101 [r]=010 [s]=000 [t]=1 [u]=001 [v]=0001 [w]=011 [x]=1001 [y]=1011 [z]=1100 ) echo 'Input string' read user_input #loop over the characters if the user input for (( s=0; s<${#user_input}; s++ )); do # retrieve the value from the array and assign to a new va...

morse script 1

Last night I got it to the point where it'd take single characters of user input and play them as a long beep if 1, a short beep if 0 and error if other. It would only take one digit at a time though; a string of digits was rejected. At that stage it looked like this: #!/bin/bash echo "Enter a sequence of 1s and 0s representing dashes and dots:" read user_input for x in $user_input; do         if [[ $x = 1 ]]         then beep -l 300 -D 50         elif [[ $x = 0 ]]         then beep -l 150 -D 50         else echo "$x is not an acceptable character"         fi done I recognise that this is poorly formed. Anyway, I need it to iterate over each character in the user input. I see references to sed and awk and whatnot, and I don't understand that stuff, so I'm going to use the most basic form I can. I found the answer here : You...