简体   繁体   English

为bash开始结束或括号?

[英]begin end or brackets for bash?

I was trying to do some bash programming and wanted to make it somewhat structural. 我试图做一些bash编程,并希望使它有点结构化。 My questions is if I want to make a block code embedded in a bracket like the Pascal begin & end or the C {}, just to put a logically atomic group of commands together, is there a way in BASH to do it. 我的问题是,如果我想在像Pascal begin&end或C {}这样的括号中嵌入一个块代码,只是为了将一个逻辑原子组的命令组合在一起,BASH中有没有办法做到这一点。

I can think of using a vacuous conditional or loop, but it's kind of ugly. 我可以想到使用一个空的条件或循环,但它有点难看。

Thanks 谢谢

Bash supports braces. Bash支持大括号。

{
  cmd1
  cmd2
}

Note that there must be a command separator before the closing brace. 请注意,在右大括号之前必须有一个命令分隔符。

{ cmd1 ; cmd2 ; }

Bash doesn't really have variable scoping, so besides flow control, I don't think you will achieve much. Bash并没有真正的变量范围,所以除了流量控制之外,我认为你不会有太大的成就。 Why not use some functions? 为什么不使用一些功能?

Note that bash blocks aren't "atomic" in any particular sense. 请注意,bash块在任何特定意义上都不是“原子的”。 See the bash manual page (ie run man bash if on a unix system), or look it up online: 请参阅bash手册页(例如,如果在unix系统上运行man bash ),或在线查找:

http://www.gnu.org/software/bash/manual/bashref.html

You should start in section 3.2.4, Compound Commands. 您应该从第3.2.4节“复合命令”开始。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM