7.5 bashの環境の表示
このスクリプトは、Bourneシェルのsetコマンドの出力から、シェル関数の定義を取り除きます。
#!/bin/sh
set | sed -n ' :x
# if no occurrence of ‘=()’ print and load next line
/=()/! { p; b; }
/ () $/! { p; b; }
コード内の説明(日本語訳)
「=()」がなければ、その行を出力して次の行を読み込みます。
# possible start of functions section # save the line in case this is a var like FOO="() " h
コード内の説明(日本語訳)
関数セクションの開始候補です。FOO="() "のような変数である可能性に備えて、その行を保存します。
# if the next line has a brace, we quit because
# nothing comes after functions
n
/^{/ q
コード内の説明(日本語訳)
次の行に波括弧があれば終了します。関数の後には何も続かないためです。
# print the old line x; p
コード内の説明(日本語訳)
前の行を出力します。
# work on the new line now x; bx '
コード内の説明(日本語訳)
今度は新しい行を処理します。