Unix - Special Variables

Unix special variables are pre-defined system variables that store specific values used in different scenarios to execute a command or script. Some of the commonly used special variables in Unix are:

$0: It is a special variable that holds the name of the shell script or command being executed.

$1, $2, $3...: These variables hold the arguments passed to a shell script or command. $1 holds the first argument, $2 holds the second argument, and so on.

$#: This variable holds the total number of arguments passed to a shell script or command.

$*: It is a special variable that holds all the arguments passed to a shell script or command in a single string.

$?: This variable holds the exit status of the last executed command or script. If the command or script executed successfully, it holds a value of 0, else a non-zero value.

$USER: It holds the username of the current user.

$HOME: It holds the home directory of the current user.

These special variables play an essential role in shell scripting and help in passing values between commands and scripts.