By default variables are strings, but can be declared with the "declare" builtin to be 64 bit ints (-i), single dimensional arrays (-a), or associative arrays (-A).
declare
-i
-a
-A
Variables are declared with name=[value]. If no value is specified, the default is the empty string.
=
let expression [expression...]
let
readonly variable declare -r variable
readonly
declare -r
local expression
local
name[index]=[value] name=( values... );
[
]=
=(
);
x="string"; declare -i n=1235; let n=5; let n++; declare -a a=("a" "b" "c"); a[0]="a"; declare -A aa=([a]="v1" [b]="v2") aa[a]="v1";
Each process maintains a set of variables called the environment, these are name/value pairs (strings only.)
In bash, variables that you want in the environment are "exported" using the 'export' built-in. i.e.: export PATH=$PATH:.
export
export PATH=$PATH:.
> printenv [name] > env
> printenv
> env
> unset [-vf] [name ...]
> unset
-vf
-v
-f
$?
$#
argc
$0
$1
argv
IFS
$*
$@
$$
$!
RANDOM
PATH
:
{
..
}
$
${
]}
[*]}
[@]}
${#
${!
:-
:=
:?
#
##
%
%%
/
^
^^
,
,,
$(command) or `command`
$(
)
$(( expression ))
$((
))
Functions are like self-contained "scripts", i.e. arguments to the function are the positional parameters ($1 .. $n), and they return an integer exit value (via return.)
return
function name { ... }
function
name () { ... }
() {
while list; do list; done
while
; do
; done
until list; do list; done
until
for name [ [ in [ word ...] ] ; ] do list ; done
for
in
;
do
for (( expr1; expr2; expr3 )) ; do list ; done
for ((
)) ; do
{}
done
break [n];
break
continue [n];
continue
if list; then list; [elif list; then list;] ... [else list;] fi
if
; then
elif
else
fi
case word in [ [(] pattern [ | pattern] ... ) list ;; ] ... esac
case
(
|
;;
esac
select name [ in word ]; do list ; done
select
alias name='value'
alias
='
'
bg [job specifier]
bg
fg [job spec]
fg
jobs
echo [strings]
echo
printf [-vvar] format [arguments]
printf
read [-p prompt] [-s] [-n nchars] names
read
-p
-s
-n
test
]
[[
]]
help test
if [[ -f <file> ]]; then echo "is a regular file"; fi
source file [params] or . file [params]
source
.