I need to grab the name of a city from an argument list. The argument list can be several words long and would look something like this:
Code:
Cheery Creek Dam 2.7 ESE, CO
Byers 0.1 N, CO
Commerce City 9 ENE, CO
If I should pass each one of the above to my function, I would like to store the city name (i.e., "Cheery Creek Dam" or "Byers" or "Commerce City") into a variable for use later.
This is what I have so far:
Code:
#!/bin/bash
function test ()
{
WC=$(echo "$*" | wc -w)
COUNT=$(echo "$WC - 3" | bc)
CITY=${1-COUNT}
echo "$*"
echo "WC ..... $WC"
echo "COUNT .. $COUNT"
echo "CITY ... $CITY"
}
test Cheery Creek Dam 2.7 ESE, CO
Result:
Code:
Cheery Creek Dam 2.7 ESE, CO
WC ..... 6
COUNT .. 3
CITY ... Cherry
How can I store "Cheery Creek Dam" into the CITY variable?
-- Tony