我在bashrc中添加了以下函数: -
function cd(){
echo "user switching to" $1
cd $1
}
重新加载.bashrc后,尝试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命令时执行某些逻辑。
答案 0 :(得分:0)
您可以在bash中使用builtin
命令:
function cd(){
echo "user switching to $1"
builtin cd "$@"
}