BASH SCRIPT – COMMAND LINE ARGUMENTS (POSITIONAL PARAMETERS) – In this tutorial, you will learn how to take command line arguments in shell script with examples.
- Process of passing the input arguments to the program at the time of execution is called as command line arguments
- In shell, this is done with the help of $ symbol.
S.N | POSITIONAL PARAMETERS | DESCRIPTION |
1. | $0 | Indicates the filename itself |
2. | $1 | Indicates the first argument |
3. | $2 | Indicates the second argument |
… | ||
4. | $* | Represents the total number of input arguments which are submitted to the shell program |
5. | $# | Shows the count of total number of arguments passed to the shell program |
I. EXAMPLE OF COMMAND LINE INPUTS
1. SOURCE CODE
2. OUTPUT
II. EXAMPLE OF COMMAND LINE INPUTS – MUCH ARGUMENTS
1. SOURCE CODE
echo “————————————————-“
echo “\t\tCommand Line Arguments”
echo “————————————————-“
# check whether the command line arguments are submitted or not
if [ $# -ne 0 ]
then
echo “Total Input Arguments are Submitted: $#”
for i in $*
do
echo $i
done
else
echo “No inputs are submitted…Please submit the CMD inputs…”
fi
2. OUTPUT
OTHER TUTORIALS
-
How to convert Word to Number in Bash Script
FacebookTweetPinLinkedInEmailShares0SharePrint In this bash tutorial, you will get convert word to number in bash script with examples.This is implemented using for loop, tr command, switch case in shell…
-
How to Count Word Frequency in Bash Script
FacebookTweetPinLinkedInEmailShares0SharePrint In this bash tutorial, you will get the program about how to count word frequency in bash script. This is done by using for loop,…
-
Bash Script – How to convert Number to Words
FacebookTweetPinLinkedInEmailShares0SharePrint In this tutorial, you will see how to convert numbers to words using bash script. This shell script can be done with the help of switch case…