Problem Statement
How do you assign and access a variable in bash?
Explanation
Variables in bash are assigned without spaces around equals sign: VAR=value or VAR='value with spaces'. Access variable value with dollar sign: $VAR or ${VAR} (braces for clarity). No spaces allowed around = during assignment - VAR = value causes error trying to execute VAR as command.
Quote variables to handle spaces and special characters: GREETING='Hello World'. Access: echo $GREETING outputs Hello World. Use double quotes to expand variables: echo "$GREETING, $USER" expands both variables. Single quotes prevent expansion: echo '$GREETING' outputs literal $GREETING.
Braces clarify variable names especially with concatenation: ${VAR}suffix prevents ambiguity. Unset variables with unset VAR. Read-only variables: readonly VAR=value or declare -r VAR=value prevents modification. Check if variable set: [ -z "$VAR" ] tests if empty/unset. Understanding variable syntax is fundamental to shell scripting.
