Bash - Loop

Bash Liste Des Attaques Ovh

About

The loop structures in Bash are:

You can use the break and continue statement to control the loop behavior.

Example

Atomic String

When calling a loop, quote the variable otherwise bash will not see the string as atomic.

output_args()
{
  for arg
  do
    echo "$arg"
  done
}
var="hello Nico"

echo "Without Quotes"
echo "**************"
output_args $var
echo 
echo "With Quotes"
echo "**************"
output_args "$var"
Without Quotes
**************
hello
Nico

With Quotes
**************
hello Nico

Parsing of command output

ls -l | while IFS=" " read -r permission child owner group size monthDate dayDate rest; do
    echo Line: 
    echo '    - Permission: '$permission
    echo '    - Child: '$child
    echo '    - Owner: '$owner
    echo '    - Group: '$group
    echo '    - Size: '$size
    echo '    - Month of Date: '$monthDate
    echo '    - Day of Date: '$dayDate
    echo '    - Rest: '$rest
done
Line:
    - Permission: -rw-r--r--
    - Child: 1
    - Owner: root
    - Group: root
    - Size: 1849173
    - Month of Date: May
    - Day of Date: 13
    - Rest: 2015 unixODBC-2.3.2.tar.gz
Line:
    - Permission: -rwxr-xr--
    - Child: 1
    - Owner: oracle
    - Group: oinstall
    - Size: 457
    - Month of Date: May
    - Day of Date: 16
    - Rest: 2017 whileDemo.sh





Discover More
Bash Liste Des Attaques Ovh
Bash - Break

A flow command that exit from within: a for, while, until, or select loop. where: n is the break level. n must be ≥ 1. If n is greater than the number of enclosing loops, all...
Bash Liste Des Attaques Ovh
Bash - Flow statement (Control Structure)

Bash - Flow statement (Control Structure) The words that control the flow of statement (ie condition and loop). help * * * * * * see * * ...
Bash Liste Des Attaques Ovh
Bash - For Statement

The for statement in bash forloop statements of Bash With a file. Locate returns a list of file in one line separated by a space. This code use then the loop array loop with the Bash version...
Bash Liste Des Attaques Ovh
Bash Shell and (Unix|Linux) Utilities (XCU)

Bash is: Bourne-Again shell (Os Shell). It means that this is scripting language used in a terminal based around The articles of this section are over: the Bash (Bourne-Again Shell) the...



Share this page:
Follow us:
Task Runner