シェル関数内で組み込みを呼び出すときに再帰を防止: - .bashrcのリロード後は、私はbashrcに、関数の下に追加
function cd(){
echo "user switching to" $1
cd $1
}
、tempディレクトリ(任意のディレクトリ)内のCDへの試みは、再帰的なエラーの下に与える: -
user switching to temp/
user switching to temp/
user switching to temp/
user switching to temp/
user switching to temp/
user switching to temp/
user switching to temp/
user switching to temp/
user switching to temp/
bash: echo: write error: Bad address
user switching to temp/
user switching to temp/
user switching to temp/
user switching to temp/
user switching to temp/
user switching to temp/
user switching to temp/
user switching to temp/
ユーザがcdコマンドを使用するたびに、ロジックを実行したいので、メソッド名をcdにします。
FYI、 'function'キーワードは非標準であり、あなたのコードの移植性を制限します。すべてのPOSIXシェルで作業するには、それを削除して 'cd(){'で始まる関数を定義してください。 –