| シンプルコマンド(Simple Commands) |
command
|
入力されたコマンドが実行される。コマンドの終了コードが戻り値となる。
シグナルを受取って終了した場合は,戻り値は128+nとなる。
内部コマンドと同一名の外部コマンドを実行するときは,./コマンド,というようにパスを指定してコマンドを入力する。 |
| コマンドパイプライン(Pipelines) |
command1 | command2 | ...
|
コマンドが左から右に順に実行され,前のコマンドの標準出力への出力が次のコマンドの標準入力に入力される。 |
| コマンドリスト(Lists of Commands) |
command1 ; command2 ; ...
|
コマンドが左から右に順に実行される。 |
command1 & command2 & ...
|
コマンドが左から右に順に実行される。その際,各コマンドはバックグラウンドで実行される。 |
command1 && command2
|
コマンド1が正常終了(終了コードが0)したら,コマンド2を実行する。 |
command1 || command2
|
コマンド1が正常終了以外(終了コードが0以外)だったら,コマンド2を実行する。 |
| コマンドの繰り返し(Looping
Constructs) |
until test-commands; do
consequent-commands;
done
|
テストコマンドの終了コードが0になるまで,一連のコマンド(consequent-commands)の実行が繰り返される。 |
while test-commands; do
consequent-commands;
done
|
テストコマンドの終了コードが0である間,一連のコマンド(consequent-commands)の実行が繰り返される。 |
for name [in words ...]; do
consequent-commands;
done
|
wordsが展開され,その値が順にnameの値となって一連のコマンド(consequent-commands)が繰り返し実行される。
in wordsが省略されると,in $@と見なされる。
|
| 条件分岐(Conditional Constructs) |
if test-commands; then
consequent-commands;
[elif test-commands; then
consequent-commands;]
[else
consequent-commands;]
fi
|
test-commandsの実行結果が0ならconsequent-commandsを実行する。 |
case word in
[(] pattern [| pattern]...) command-list ;;
[[(] pattern [| pattern]...) command-list ;;]
esac
|
wordの値が一致するところのcommand-listが実行される。 |
select name [in words ...]; do
commands;
done
|
wordsが展開され,その値が標準エラー出力に出力される。そこから選択した値がnameの値となり,コマンドが実行される。 |
(( expression ))
|
式(expression)を評価し,その結果が0以外なら0(true)を返し,0なら1(false)を返す。 |
[[ expression ]]
|
|
| グルーピング(Grouping Commands) |
( list )
|
サブシェルが起動され,コマンドリストが実行される。 |
{ list }
|
カレントシェルのなかでコマンドリストが実行される。 |
| シェル関数(Shell Functions) |
[ function ] name () {
command-list;
}
|
手続きを定義する。
定義した手続きは通常のコマンド実行と同じようにして呼び出す。その際渡した引数は手続き中ではポジショナルパラメータとして扱われる。
|