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


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 `('

最新更新