To know the list of these variables in your system, type the commands set, env, and printenv on the command line terminal as follows:
printenv # shows all environment variables
env # same as above
set # shows all shell + user-defined variables
================================================
prabhumanyam@PrabhuPC:~$ cat sysvariables.sh
#!/bin/bash
# ---------------------------------------------
# Script Name: system_vars.sh
# Purpose: Display common system-defined variables
# ---------------------------------------------
echo "===== SYSTEM-DEFINED VARIABLES ====="
echo "User Name : $USER"
echo "Home Directory : $HOME"
echo "Current Shell : $SHELL"
echo "Current Directory : $PWD"
echo "Previous Directory : $OLDPWD"
echo "Hostname : $HOSTNAME"
echo "User ID (UID) : $UID"
echo "Effective UID : $EUID"
echo "Path Variable : $PATH"
echo "Terminal Type : $TERM"
echo "Process ID (PID) : $$"
echo "Script Name : $0"
echo "Number of Arguments: $#"
echo "All Arguments (*) : $*"
echo "All Arguments (@) : $@"
echo "Last Command Status: $?"
echo "Random Number : $RANDOM"
echo "Last Background PID: $!"
echo "Line Number : $LINENO"
echo "Seconds Since Start: $SECONDS"
echo "today is";date
echo "no of users logged in"; who | wc -l
echo "calender"; cal
echo "---------------------------------------------"
prabhumanyam@PrabhuPC:~$ sh sysvariables.sh sandeep pr hari manyam 100 200
===== SYSTEM-DEFINED VARIABLES =====
User Name : prabhumanyam
Home Directory : /home/prabhumanyam
Current Shell : /bin/bash
Current Directory : /home/prabhumanyam
Previous Directory :
Hostname :
User ID (UID) :
Effective UID :
Path Variable : /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program Files/Common Files/Oracle/Java/javapath:/mnt
Terminal Type : xterm-256color
Process ID (PID) : 5669
Script Name : sysvariables.sh
Number of Arguments: 6
All Arguments (*) : sandeep pr hari manyam 100 200
All Arguments (@) : sandeep pr hari manyam 100 200
Last Command Status: 0
Random Number :
Last Background PID:
Line Number :
Seconds Since Start:
today is
Thu Nov 13 08:06:08 UTC 2025
no of users logged in
1
calender
November 2025
Su Mo Tu We Th Fr Sa
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
================================================
| Variable | Description | Example Output |
|---|---|---|
$HOME | Home directory of the current user | /home/prabhu |
$USER | Username of the logged-in user | prabhu |
$PATH | List of directories the shell searches for executables | /usr/local/bin:/usr/bin:/bin:/usr/sbin |
$PWD | Current working directory | /home/prabhu/scripts |
$OLDPWD | Previous working directory | /home/prabhu |
$SHELL | Path of the user’s login shell | /bin/bash |
$UID | User ID number of the current user | 1000 |
$EUID | Effective User ID (useful when running with sudo) | 0 for root |
$0 | Name of the current script | ./myscript.sh |
$# | Number of command-line arguments passed to the script | 3 |
$* | All command-line arguments as a single string | arg1 arg2 arg3 |
$@ | All command-line arguments as separate strings | arg1 arg2 arg3 |
$$ | Process ID (PID) of the current shell/script | 5472 |
$? | Exit status of the last executed command (0 = success) | 0 |
$! | PID of the last background process | 5501 |
$HOSTNAME | Name of the machine | PrabhuPC |
$RANDOM | Generates a random number each time it’s referenced | 26485 |
$LINENO | Current line number in the script | 12 |
$SECONDS | Number of seconds the shell has been running | 45 |