bash - 无法识别 .bashrc 中定义的函数

标签 bash function shell

我试图让下面的函数从 bash session 中可用,所以我将它添加到 .bashrc :

function del () { mkdir -p ~/.trash; mv "$@" ~/.trash; }
这在 shell 脚本中工作正常,但是当我调用 .bashrc 时来自终端的版本,例如:
$ del test.txt
我总是得到这个:

bash: syntax error near unexpected token `test.txt'


我正在执行 source ~/.bashrc每次更改文件时,我已经尝试了不同的编写函数的方法,它有什么问题?它在 .sh 文件中工作,所以可能需要 .bashrc 的特殊语法?
编辑
事实证明,即使在获取 .bashrc 之后, session 仍保留了一个同名的旧别名。再次。 type del帮助我检测到它。运行 unalias del或者开始一个新的 session 解决了这个问题。

最佳答案

来自 OP 修正后的结束段落:

Turns out that the session kept an old alias with the same name, even after sourcing .bashrc again. Type del helped me detecting it. Running unalias del or starting a new session solved the problem.



(这个答案的存在只是为了让这个 Q 不属于未回答的类别。)

关于bash - 无法识别 .bashrc 中定义的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42041511/

相关文章:

arrays - 将文件中的行读入 Bash 数组

bash - 循环两组文件

c++ - typedef 和函数声明错误

linux - 使用 sed 将一个单词替换为两个单词和一个空格

svn - 阻止命令 "del/s"进入文件夹

Python:为类的任何方法做些什么?

c - 将值从一个函数传递给C中的另一个函数

regex - 在 sed 的正则表达式中转义美元符号

c - 如何在不考虑空格的情况下运行 bash 命令

shell - chmod: ‘og=’ 之后缺少操作数 Gitlab CI/CD executor=shell