加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

是什么导致此bash语法错误?

发布时间:2020-12-15 21:35:57 所属栏目:安全 来源:网络整理
导读:此命令在命令行上正常工作… if g++ -std=c++11 main.cpp ; then ./a.out; fi 但是当我尝试将它作为函数添加到我的.bashrc时它失败了…… function cgo() { if g++ -std=c++11 "$1" ; then ./a.out; fi }$cgo main.cppbash: syntax error near unexpected to
此命令在命令行上正常工作…

if g++ -std=c++11 main.cpp ; then ./a.out; fi

但是当我尝试将它作为函数添加到我的.bashrc时它失败了……

function cgo() { if g++ -std=c++11 "$1" ; then ./a.out; fi }

>$cgo main.cpp
bash: syntax error near unexpected token `main.cpp'

我在这做错了什么?

解决方法

使用{braces}时,需要在闭括号之前使用换行符或分号.对于单行,这意味着你需要一个分号

function cgo() { if g++ -std=c++11 "$1" ; then ./a.out; fi; }
# ........................................................^

文档:https://www.gnu.org/software/bash/manual/bashref.html#Command-Grouping

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读