首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在调用shell函数内部的内建器时防止递归

在调用shell函数内部的内建器时防止递归
EN

Stack Overflow用户
提问于 2017-05-13 20:37:26
回答 1查看 47关注 0票数 2

我在bashrc中添加了以下函数:

代码语言:javascript
复制
function cd(){
        echo "user switching to" $1
        cd $1
}

在重新加载.bashrc之后,尝试在临时目录(任何目录)中尝试cd会出现以下递归错误:-

代码语言:javascript
复制
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,因为我希望执行一些逻辑。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-13 20:40:26

您可以在bash中使用builtin命令:

代码语言:javascript
复制
function cd(){
        echo "user switching to $1"
        builtin cd "$@"
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43957758

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档