programming-languages:bash:variables
Variables
All variables are treated as strings.
Important: when declaring a variable, no space should be used around =
.
Using the $
symbol, the value of a variable, command, or calculation is expanded.
#!/bin/bash x=1 y=2 w=this s="is a string" a=$((x + y)) # expand each var and expand the arithmetic calc echo $a b="$w $s" # expand each var and concatenate them echo $b c=$(date '+%A %d %B, %H:%M') # expand the result of a command echo $c
Info: for command evaluations use single brackets (..)
, while for arithmetic evaluations use double brackets ((..))
. In the latter case the $
symbol before the variable names can be omitted.
programming-languages/bash/variables.txt · Last modified: 2023/11/01 10:55 by tormec