sharon paul
sharon paul

Reputation: 93

how to repeat the process in shell script

Hi i am new to shell script.in my shell script i want to repeat the process.

script.sh
echo "Enter the city name"
read cityname
echo "Enter the state name"
read statename
pig -x mapreduce mb_property_table_updated.pig city=$cityname state=$statename
echo "Do you want to run for another city"

if yes means i want to repeat the processs again else it will move to next process.any help will be appreciated.

Upvotes: 0

Views: 467

Answers (3)

chepner
chepner

Reputation: 531275

For completeness, there is also an often overlooked until loop in shell.

until [ "$answer" = no ]; do
    echo "Enter the city name"
    read cityname
    echo "Enter the state name"
    read statename
    pig -x mapreduce mb_property_table_updated.pig city=$cityname state=$statename
    echo "Do you want to run for another city"
    read answer
done

Upvotes: 0

beny23
beny23

Reputation: 35018

I'd do something like this:

while [ "$e" != "n" ]; do
    echo "Enter the city name"
    read cityname
    echo "Enter the state name"
    read statename
    pig -x mapreduce mb_property_table_updated.pig city=$cityname state=$statename
    echo "Do you want to run for another city (y/n)"
    read e
done

Upvotes: 1

Shravan Yadav
Shravan Yadav

Reputation: 1317

use while loop

line=yes
while [ "$line" = yes ]
do
echo "Enter the city name"
read cityname
echo "Enter the state name"
read statename
pig -x mapreduce mb_property_table_updated.pig city=$cityname state=$statename
echo "Do you want to run for another city"
read line
done

And also in for loop

for((;;))
do
echo "Enter the city name"
read cityname
echo "Enter the state name"
read statename
pig -x mapreduce mb_property_table_updated.pig city=$cityname state=$statename
echo "Do you want to run for another city"
read answer
if [ "$answer" = "yes" ]
then
continue
else
break
fi
done

Upvotes: 1

Related Questions