Linux-Bash-Loops-branch

2017-06-15  本文已影响0人  tarzipc

for

# 等价于 for para in $@
for para
do
  echo "$para"
done

# 当前目录下的 txt 文件
for file in *txt
do 
  echo $file
done 

select

# 如果 in list 省略,将使用 $@
select variable [in list]
do 
 command... 
 break 
done

# 

PS3='Choose your favorite vegetable: '
select veg in "beans" "carrots" "potatoes"
do
    if [ -z $veg ]
    then
        echo "Sorry. That is not on the menu."
        continue
    else
        echo
        echo "Your $veg"
        echo
    fi
    break
done

上一篇下一篇

猜你喜欢

热点阅读