Shell variables

A shell variable is a variable that is used within a shell environment to store data such as strings, numbers, or the output of commands. Shell variables are essential components of shell scripting and interactive shell usage, allowing you to hold and manipulate information while working in a Unix-like system (such as Linux or macOS).

Key characteristics of shell variables:

Local to the shell session: Shell variables exist only within the session in which they are created and are not automatically passed to other processes or subshells unless exported. Dynamic typing: Shell variables are not explicitly typed, meaning they can store any kind of value (string, integer, etc.) without needing to declare a specific type. Case-sensitive: Shell variable names are case-sensitive. For example, VAR and var are two distinct variables. Assigned using =: You assign a value to a shell variable using the = operator, and there should be no spaces between the variable name, the = sign, and the value.

export				    # export a VAR to sub shells and sub processess
printenv  			    # list all variables on bash like $PATH, $HOME, $DISPLAY
unset VAR_NAME			# drop VAR_NAME from bash
env 				    # list all variables on bash like $PATH, $HOME, $DISPLAY
env VAR=value cmd 		# Run cmd with new value of VAR 
echo $?                 # returns exit status code of last command