本文介绍了是什么导致此bash语法错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此命令在命令行上工作正常...
This command works fine on the command line...
if g++ -std=c++11 main.cpp ; then ./a.out; fi
但是当我尝试将其作为功能添加到我的.bashrc中时,它会失败...
But when I try to adding it to my .bashrc as a function it fails...
function cgo() { if g++ -std=c++11 "$1" ; then ./a.out; fi }
>$ cgo main.cpp
bash: syntax error near unexpected token `main.cpp'
我在做什么错了?
推荐答案
使用 {大括号}
时,需要在右大括号前使用换行符或分号.对于单行代码,这意味着您需要用分号
When using { braces }
you need to have a newline or semi-colon before the close brace. For one-liners, that means you need a semi-colon
function cgo() { if g++ -std=c++11 "$1" ; then ./a.out; fi; }
# ........................................................^
文档: https://www.gnu.org/software/bash/manual/bashref.html#Command-Grouping
这篇关于是什么导致此bash语法错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!