thor
thor

Reputation: 22460

begin end or brackets for bash?

I was trying to do some bash programming and wanted to make it somewhat structural. 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.

I can think of using a vacuous conditional or loop, but it's kind of ugly.

Thanks

Upvotes: 2

Views: 2853

Answers (3)

Alex North-Keys
Alex North-Keys

Reputation: 4363

Note that bash blocks aren't "atomic" in any particular sense. See the bash manual page (i.e. run man bash if on a unix system), or look it up online:

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

You should start in section 3.2.4, Compound Commands.

Upvotes: 0

mogul
mogul

Reputation: 4553

Bash doesn't really have variable scoping, so besides flow control, I don't think you will achieve much. Why not use some functions?

Upvotes: 0

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798486

Bash supports braces.

{
  cmd1
  cmd2
}

Note that there must be a command separator before the closing brace.

{ cmd1 ; cmd2 ; }

Upvotes: 5

Related Questions