简体   繁体   English

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

[英]syntax error near unexpected token `(' when defining function in bash profile

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

This function is in my bash profile, and it raises an error when I try to source the file. 此函数在我的bash配置文件中,当我尝试获取该文件时会引发错误。

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

I can't figure out why. 我不知道为什么。 I have another function that looks like this and doesn't raise any error: 我有另一个函数,看起来像这样,不会引发任何错误:

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

        mkdir -p $testFolderPath
        cp $abcFilePath $testFilePath
}

What is wrong with my function definition? 我的函数定义有什么问题?

This can happen if gac is already an alias. 如果gac已经是别名,则可能发生这种情况。 For example on my machine: 例如在我的机器上:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 BASH函数:意外标记“2”附近的语法错误 - BASH function: syntax error near unexpected token `'2'' .bash_profile 中意外标记“then”附近的语法错误 - syntax error near unexpected token `then' in .bash_profile 将数组传递给Bash中的函数:意外令牌'('附近的语法错误 - Passing array to a function in Bash: syntax error near unexpected token `(' bash:使用 virtualenv 时出现意外标记“(”附近的语法错误 - bash: syntax error near unexpected token `(' when using virtualenv Bash:使用Wgrib2时,语法错误接近意外的令牌`(' - Bash: Syntax Error Near Unexpected Token `(' When Using Wgrib2 选择文件时,bash 脚本中意外标记“(”附近的语法错误 - syntax error near unexpected token '(' in bash script when selecting files 意外令牌附近的语法错误“(”在bash中声明数组时 - Syntax error near unexpected token “(” when declaring arrays in bash `第 1 行:运行 bash `case` 函数时出现意外标记 `newline'` 附近的语法错误 - `line 1: syntax error near unexpected token `newline'` when run bash `case` function 意外令牌`('附近的Bash语法错误 - Bash syntax error near unexpected token `(' Windows 7意外令牌附近的Bash语法错误 - Bash syntax error near unexpected token '('. Windows 7
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM