我试图让下面的函数从 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. Typedel
helped me detecting it. Runningunalias del
or starting a new session solved the problem.
(这个答案的存在只是为了让这个 Q 不属于未回答的类别。)
关于bash - 无法识别 .bashrc 中定义的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42041511/