Monday, December 20, 2010

How can i get the name of Script that is running?

You can get the name of Script file that is run by simply:

echo $0 or
echo ${0}

$0 will contain the name of your shell script.

Other useful variables in Shell Script:

  • $$ = The PID number of the process executing the shell.
  • $? = Exit status variable.
  • $0 = The name of the command you used to call a program.
  • $1 = The first argument on the command line.
  • $2 = The second argument on the command line.
  • $n = The nth argument on the command line.
  • $* = All the arguments on the command line.
  • $# The number of command line arguments.
A very useful command when working with command line arguments is "shift". With this the command line arguments are shifted by certain number of places. For e.g., if you execute shift 1. $1 becomes $2 and so on....

No comments:

Post a Comment