Thursday 26 January 2012

command line arguments

This is just to demonstrate the command line arguments in a shell script

#!/bin/bash

# Script that demonstrate, command line arguments

echo "Total number of command line argument are: $#"

echo "script name is: $0"

echo "$1 is first argument"

echo "$2 is second argument"

echo "All of them are :- $* or $@"

# sh filename.sh 1 2 3 4 5 (arguments)

$* - This denotes all the parameters passed to the script at the time of its execution

$@ - denotes all the parameters passed to the script at the time of its execution

$0 - Name of the shell script being executed

$$ - Pid of current process

$# - Number of arguments specified in the command line

$? - Exit status of the last command

To see the process Id of the current shell
# echo $$ 
 
Exit status of a command 
# echo $?

The above symbols are known as positional parameters.

No comments:

Post a Comment