How do you define an Anonymous Block of Code in Bash?

Bash Liste Des Attaques Ovh

About

This page shows you how to define a block of code in bash

A non-anonymous block is a function.

What is the syntax?

The block syntax is:

{

   # your code
   
}

Example

Redirect Stdout

{
    cat <<-EOH
       #
       # THIS IS A comment
       #
    EOH
    echo Another
} > "/path/to/file"

Can I use the subshell syntax?

You can use the subshell syntax but you will not get any return status (meaning that you can't exit)

(

   # your code
   
)





Discover More
Bash Liste Des Attaques Ovh
Bash - Read (Builtin Command) that capture a line

Read is a bash builtin command and read: by default one line or a number of characters (by option) from: the standard input, or from the file descriptor fd supplied as an argument to the...
Bash Liste Des Attaques Ovh
Bash - local - Variable declaration in function - (Builtin)

local variable scoping declaration inside a block or a function. It is an error to use local when not within a function. For each argument, a local variable named name is created, and assigned value....
Bash Liste Des Attaques Ovh
What are Control Operators in Bash?

A control operator is a separator in a list of command that controls the execution of the commands. They implement: Boolean operator Block syntax End of statement Pipe operators A token that...



Share this page:
Follow us:
Task Runner