Skip to content
  • About
  • CoursesExpand
    • Problem Solving using C Language
    • Mastering Database Management
    • Linux System Administration
    • Linux and Shell Programming
  • Publications
  • Professional Certificates
  • BooksExpand
    • Books Authored
  • Patents
Download CV
“BCE-C712 Linux System Administration” has been added to your basket. Continue shopping

Unix Special Variables

Special Variables

Sr. No.Variable & Description
1.$0 – The filename of the current script.
2.$n – These variables correspond to the arguments with which a script was invoked. Here n is a positive decimal number corresponding to the position of an argument (the first argument is $1, the second argument is $2, and so on).
3.$# – The number of arguments supplied to a script.
4.$* – All the arguments are double quoted. If a script receives two arguments, $* is equivalent to $1 $2. It takes input as string. For difference, run the script /unix-variable-and-difference/
5.$@ – All the arguments are individually double quoted. If a script receives two arguments, $@ is equivalent to $1 $2.  It takes input as array.
6.$? – The exit status of the last command executed. Output ‘0’ if all successful ‘1’ if unsuccessful.
7.$$ – The process number of the current shell. For shell scripts, this is the process ID under which they are executing.
8.$! – The process number of the last background command.
9.$1-$9 – Command Line Arguments

Example

File Name: specialchar.sh

#!/bin/sh

echo “File Name: $0”
echo “First Parameter : $1”
echo “Second Parameter : $2”
echo “Quoted Values: $@”
echo “Quoted Values: $*”
echo “Total Number of Parameters : $#”

Command to Run: ./specialchar.sh Nishant Munjal

Scripts

Nishant Munjal

Coding Humanity’s Future </>

Facebook Twitter Linkedin YouTube Github Email

Tools

  • SIP Calculator
  • Write with AI
  • SamplePHP
  • Image Converter

Resources

  • Blog
  • Contact
  • Refund and Returns

Legal

  • Disclaimer
  • Privacy Policy
  • Terms and Conditions

© 2025 - All Rights Reserved

  • About
  • Courses
    • Problem Solving using C Language
    • Mastering Database Management
    • Linux System Administration
    • Linux and Shell Programming
  • Publications
  • Professional Certificates
  • Books
    • Books Authored
  • Patents
Download CV
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok