Linuxコマンド集 |
コマンド集(機能別) | コマンド集(アルファベット順) | コマンド逆引き大全 | シェル・スクリプト・リファンレス |
select | ループ制御構造を作る | (Shell) |
構文 | |
select 変数名 in リスト名 do コマンド done |
説明 | |
メニューを作成するのに使えるコマンド。リストに指定された文字列を番号付きで表示し,ユーザーからの番号入力を待つ。番号を指定すると,番号自体は組み込み変数REPLYに,選択された文字列が変数に入る。in リスト名を省略することもできる。その後,コマンドを実行する。変数を参照するコマンドを記述する場合が多い。 |
使用例 | |
簡易システム管理メニューの例
list="df du ps (exit)"
select command in $list
do
if [ "$command" = "df" ]; then
clear
df -h
echo
elif [ "$command" = "du" ]; then
clear
du / | sort -nr | head
echo
elif [ "$command" = "ps" ]; then
clear
ps -e | more
echo
elif [ "$command" = "(exit)" ]; then
clear
exit
else
clear
echo $REPLY is not in the command list.
echo
fi
done
|
関連事項 | |
break,continue,for,until,while |