Here is a list of commonly used special variables in Bash and their meanings:
$0
: Represents the name of the script or shell.$1
,$2
,$3
, …: These variables hold the positional parameters passed to the script or function.$1
represents the first parameter,$2
represents the second parameter, and so on.$#
: Holds the number of positional parameters passed to the script or function.$@
: Represents all the positional parameters passed to the script or function as separate arguments.$*
: Represents all the positional parameters passed to the script or function as a single string.$$
: Holds the process ID (PID) of the currently running script.$?
: Represents the exit status of the last executed command. A value of 0 typically indicates success, while non-zero values indicate an error.$!
: Holds the process ID (PID) of the last background command executed.$USER
: Represents the username of the current user.$HOME
: Holds the home directory path of the current user.$PWD
: Represents the current working directory.$IFS
: Internal Field Separator. Specifies the delimiter used for word splitting in shell commands.$RANDOM
: Generates a random integer between 0 and 32767.$LINENO
: Represents the current line number in the script.
These special variables provide valuable information about the script’s execution environment, command-line arguments, process IDs, and other relevant details. They allow you to access and utilize this information within your script to make decisions, perform operations, or provide feedback to the user.