passing arguments in linux shell scripting

We can pass the parameters (arguments) to shell script delimited by white spaces. You can access the current script name and arguments using $0, $1,$2….and so on.
  • $0 = Script name (also called as base name of file)
  • $1 = First argument to the script
  • $2 = Second argument to the script and so on..
In the script, we can access count of arguments using $#
if [ $# < 2 ]
          echo “Count of parameters is less than 2”
exit -1

We can use below special variables to access the parameters.
  • [email protected] – All of the arguments.
  • $* – All of the arguments. This does not preserve the white space and quotes.
Another variables that start with $ are given below.
  • $$ – This gives you the process id of current shell.
  • $! – This gives you the process id of last background process.

Web development and Automation testing

solutions delivered!!