如何在 shell 脚本中重复该过程

how to repeat the process in shell script

嗨,我是 shell script.in 我的 shell 脚本的新手,我想重复这个过程。

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"

如果是意味着我想再次重复该过程,否则它将移至下一个 process.any 帮助将不胜感激。

使用 while 循环

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

并且也在 for 循环中

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

我会这样做:

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

为了完整起见,shell中还有一个经常被忽视的until循环。

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