Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在shell脚本中重复该过程_Shell_Sh - Fatal编程技术网

如何在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

您好,我是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"
如果是,表示我想再次重复这些过程,否则将转到下一个过程。如有任何帮助,将不胜感激。

使用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中可能不可用。