bash - 在 bash 配置文件中定义函数时出现意外标记 `(' 附近的语法错误

标签 bash function alias

gac() {
        git add .
        git commit -m "$1"
}

这个函数在我的 bash 配置文件中,当我尝试获取文件时它会引发错误。

$ source ~/.bashrc
bash: /home/sahandz/.bashrc: line 176: syntax error near unexpected token `('
bash: /home/sahandz/.bashrc: line 176: `gac() {'

我不知道为什么。我有另一个函数,看起来像这样并且不会引发任何错误:

abcToTestDir() {
        folderName=${1%_*}
        testFolderPath="$testfilespath$folderName"
        abcFilePath="$abcpath$folderName/$1"
        testFilePath="$testFolderPath/$1"

        mkdir -p $testFolderPath
        cp $abcFilePath $testFilePath
}

我的函数定义有什么问题?

最佳答案

如果 gac 已经是一个别名,就会发生这种情况。例如在我的机器上:

$ type ls
ls is aliased to `ls --color=auto'
$ ls(){ true; }
bash: syntax error near unexpected token `('

关于bash - 在 bash 配置文件中定义函数时出现意外标记 `(' 附近的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56408356/

相关文章:

javascript - 如何点击具体坐标?

托管 Apache 的 Django 静态文件

ruby - 我应该使用 alias 还是 alias_method?

mysql:获取具有最大列值的别名的元组

Mysql函数返回系统结果

string - 你如何追加到一个已经存在的字符串?

从 C (double)、GAS 调用 ASM x64 函数

bash - 使用 Go 运行带参数的 bash 文件

git - 将 "current"git 标签写入文本文件

r - R中的模块化编程