You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Linux, several special variables (also called shell variables or environment variables) are commonly used when working with the command line and scripting. Here are the most important ones you should know:
1. Positional Parameters (Command-line Arguments)
Variable
Description
$0
The name of the script or command being executed.
$1, $2, ..., $9
The first, second, ..., ninth argument passed to the script.
${10}, ${11}, ...
Arguments beyond the ninth (must be enclosed in {}).
$*
All arguments passed to the script as a single string.
$@
All arguments passed to the script as separate strings.
Script Name: ./script.sh
First Argument: Hello
Second Argument: World
All Arguments ($*): Hello World
All Arguments ($@): Hello World
Total Arguments: 2
2. Exit Status and Process Control
Variable
Description
$?
Exit status of the last executed command.
$$
Process ID (PID) of the current script or shell.
$!
Process ID of the last background job.
$-
Current shell options (set using set -o).
Example: Check PID
echo"Current Process ID: $$"
sleep 10 &echo"Background Process ID: $!"