Table of Contents

About

A variable in bash is called a parameter.

There is three different type of parameter

A parameter can be then referenced by:

  • a name,
  • a number
  • or a special symbol (Special Character)

A parameter is set if it has been assigned a value. (The null string is a valid value)

Management

See also Bash - Parameter Expansion ${

Check if set

  • -z string has zero length
if [ -z ${var+x} ]; then
  echo "var is unset"; 
else 
  echo "var is set to '$var'"; 
fi

where

or -n: string is not null

if [ -n ${var+x} ]; then
  echo "var is set to '$var'"; 
else 
  echo "var is unset"; 
fi