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 '
今度は新しい行を処理します。