Some comments
1) rather than calling the script recursively, it would be more natural to put the thing you want done inside the loop - if you want to preserve the existing script structure you could simply define that as a function
Code:
function doit() {
read -p "Enter the abbreviation of the currency you want to convert from: " -ei "SEK" convfrom
read -p "Enter the abbreviation of the currency you want to convert to: " -ei "USD" convto
read -p "Enter the amount you want to convert: " -ei "1" convamount
wget -q -O - "http://www.google.com/finance/converter?a=$convamount&from=$convfrom&to=$convto" | grep "<div id=currency_converter_result>" | sed 's/<[^>]*>//g'
}
(I made the reads interactive so that instead of 'Ex. SEK' it actually pre-fills 'SEK' as the default value) and then instead of recursing, have a loop like
Code:
echo "This script is for getting the current exchange rate"
doit
while true; do
doit
done
2) a case statement makes it easy to handle the x = Q or R input, and even to make it case-insensitive - something like
Code:
echo "This script is for getting the current exchange rate"
doit
while : ; do
read -p "Press R to run the script again or Q to quit. " -n1 x
echo
case "$x" in
R|r) doit
;;
Q|q) exit
;;
*) echo "Please enter R or Q"
;;
esac
done
(I made another suggestion about the read, using -n1 so it's a true key press rather than waiting for a newline - see 'help read')
Bookmarks