쉘 기능을 내부에 내장을 호출 할 때 재귀를 방지 : - .bashrc에 다시로드 한 후내가 bashrc에에 기능 아래에 추가
function cd(){
echo "user switching to" $1
cd $1
}
, 임시 디렉토리 (디렉토리)에서 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로 지정합니다.
참고로,은'function' 키워드가 비표준이며, 코드의 이식성을 제한합니다. 모든 POSIX 셸에서 작업하려면 제거하고'cd() {'로 시작하는 함수를 정의하십시오. –