Bash - For Statement

Bash Liste Des Attaques Ovh


The for statement in bash

As the for statement is a loop statement, you may be interested to check the other loop statements of Bash


How to loop over a list of file

With a file.

Locate returns a list of file in one line separated by a space. This code use then the for_name_in_word loop

for n in `locate myfile`
    echo $n



for n in {0..5}
  echo "BASH_VERSINFO[$n] = ${BASH_VERSINFO[$n]}"
# BASH_VERSINFO[0] = 3                      # Major version no.
# BASH_VERSINFO[1] = 00                     # Minor version no.
# BASH_VERSINFO[2] = 14                     # Patch level.
# BASH_VERSINFO[3] = 1                      # Build version.
# BASH_VERSINFO[4] = release                # Release status.
# BASH_VERSINFO[5] = i386-redhat-linux-gnu  # Architecture
                                            # (same as $MACHTYPE).

for name in word

for name [ in word ] ; do list ; done

where list is a list of commands.

The list of words following in is expanded, generating a list of items.

The variable name is set to each element of this list in turn, and list is executed each time.

If the in word is omitted, the for command executes the list of command once for each positional parameter that is set.

The return status is the exit status of the last command that executes.

If the expansion of the items following in results in an empty list, no commands are executed, and the return status is 0.

for (( expr1 ; expr2 ; expr3 ))

for (( expr1 ; expr2 ; expr3 )) ; do list ; done

First, the arithmetic expression expr1 is evaluated according to the rules described below under ARITHMETIC EVALUATION. The arithmetic expression expr2 is then evaluated repeatedly until it evaluates to zero. Each time expr2 evaluates to a non-zero value, list is executed and the arithmetic expression expr3 is evaluated. If any expression is omitted, it behaves as if it evaluates to 1. The return value is the exit status of the last command in list that is executed, or false if any of the expres- sions is invalid.

Discover More
Bash Liste Des Attaques Ovh
Bash - (Argument|Positional Parameter)

An argument is a parameter given: to a command to a function or to the bash shell They are referenced by position. A positional parameter is a parameter denoted: by one or more digits, ...
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 - Continue

A control flow statement where: n resume at the nth enclosing loop. n must be ≥ 1. If n isgreater than the number of enclosing loops, the last enclosing loop (the ‘‘top-level’’...
Bash Liste Des Attaques Ovh
Bash - Loop

The loop structures in Bash are: for while select until You can use the break and continue statement to control the loop behavior. When calling a loop, quote the variable otherwise bash...
Bash Liste Des Attaques Ovh
Bash - Sequence

A sequence expression is a construct that creates sequence of numbers or characters. It's a brace expansion and takes the form where x and y are either: integers or single characters. A correctly-formed...
Card Puncher Data Processing
Datacadamia - Data all the things

Computer science from a data perspective
Card Puncher Data Processing
How to resize images in a directory with ffmpeg ?

This article shows you how to scale image in a dirctory with ffmpeg and conserve the aspect ratio. Because ffmpeg is a video management tool, it can also modify a frame, in other word, an image. ...
Bash Liste Des Attaques Ovh
How to use the Array Variable in Bash?

Bash provides a one-dimensional array variables. See also: When calling a function, quote the variable otherwise bash will not see the string as atomic. The separator is variable $IFS. There is: ...

Share this page:
Follow us:
Task Runner