Hello all!
I have this assignment to make the following script:
INPUT:./<scriptname> number1 number2 number3 number4
PROCESSING:Look up all the possible combinations in /usr/share/dict/words while you replace '2' with an a, b or c, '3' with d, e or f,... like in a cellphone
OUTPUT:Show matches or errormessage if no match
Sor far I have come up with this:
Code:
#!/bin/bash
if [[ $# -lt 1 ]]
then
echo "No input was given. Please enter some numbers."
exit
fi
while [[ $# -gt 0 ]]; do
if [[ $1 =~ [^2-9] ]]
then
echo "Invalid input ($1). Only numbers between 2 and 9 are allowed."
exit
else
number="$number $1"
echo "$number"
shift
fi
done
But I'm having a lot of trouble finding out how to do the actual conversion from the numbers to the letters and searching them in the word list, that is without a ridicoulously long if-then-else-structure.
Note: as you might suspected by now, my level in shell scripting is very basic
