Difference between revisions of "Bash:Variables"

From wiki
Jump to navigation Jump to search
Line 37: Line 37:
 
;$!
 
;$!
 
:ProcessID of last spawned process.
 
:ProcessID of last spawned process.
 +
 +
=Loop over a range=
 +
<syntaxhighlight lang=bash>
 +
for i in {00..59}
 +
do
 +
  echo ${i}
 +
done
 +
 +
for i in $(seq ${START} ${END})
 +
do
 +
  echo $i
 +
done
 +
</syntaxhighlight>

Revision as of 20:30, 19 April 2019


Arithmetics

Bash and ksh only work with integers.

+, -, *, /, %
add, substract, multiply, divide, modulo.
**
For bash, Exponentiation
10#00012
For bash, force the figure (00012) to be interpreted as decimal. Figures starting with 0 are considered octal by default.
expr <expr>
Voer expr uit, bij boolean wordt 1 (onwaar) of 0 (waar) gegeven
((VAR=x+y))
let VAR=x+y
VAR=$((x+y))
VAR=$(expr x + y)
Calculate and assign to VAR
let VAR+=2
Add two to VAR

Special Parameters

$0
Name current procedure
$1
First passed argument ($2 is the second, $3... )
$*
All arguments given as one string
$@
All arguments given as separate strings per parameter
$#
The number of passed arguments
$?
The returnstate for the last executed command. 0 = OK, all others not.
$$
ProcessID of current process, handy to use for temporary files
$!
ProcessID of last spawned process.

Loop over a range

for i in {00..59}
 do
  echo ${i}
 done

for i in $(seq ${START} ${END})
 do
  echo $i
 done