如何在shell脚本中重复该过程
您好,我是shell脚本新手。在我的shell脚本中,我想重复这个过程如何在shell脚本中重复该过程,shell,sh,Shell,Sh,您好,我是shell脚本新手。在我的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
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"
如果是,表示我想再次重复这些过程,否则将转到下一个过程。如有任何帮助,将不胜感激。使用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
(;)的是一个bash
ism,在shell中可能不可用。