select用法

select 语句

select表达式是bash的一种扩展应用,擅长于交互式场合。用户可以从一组不同的值中进行选择:

select var in ... ; do
 break;
done
.... now $var can be used ....

下面是select使用的例子:
1.
 
  
#!/bin/bash
##filename:what-lang-do-you-like_menu_select.sh 

clear
PS3="What is your preferred scripting language? "
select s in bash perl python ruby'(quit)'
do
        case $s in
                bash|perl|python|ruby)  echo "You selected $s ."  ;;
                '(quit)')               break ;;
                *)                      echo "You selected error,retry..."  ;;
        esac
done

select用法_第1张图片
 
  
2.
#!/bin/bash
##filename:what-lang-do-you-like_menu_select.sh 

clear
PS3="What is your preferred scripting language? "
select s in bash perl python ruby'(quit)'
do
        case $s in
                bash|perl|python|ruby)  echo "You selected $s ."  ;;
                '(quit)')               break ;;
                *)                      echo "You selected error,retry..."  ;;
        esac
done

select用法_第2张图片
 
 

你可能感兴趣的:(select用法)