May 2025
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  

Categories

May 2025
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  

Command line argument in shell script

Command line argument in shell script
Passing arguments to the main program when it start is know as command line arguments
In shell scripting arguments can be described like below

$0 – shows program name which you running
$1 – shows first argument
$2 – display second argument
$3 – display third argument
$n – n th argument
$# – shows number of arguments passed to the program
$* – shows entire string of parameters you passed

SCRIPT:
#!/bin/bash
echo “programme name is $0”
echo “first argument is $1”
echo “Second argument is $2”
echo “Total command line arguments is $#”
echo “Entered arguments was :$*”

RUN THE SCRIPT:
./cmd_arg.sh hi this is mohan

OUTPUT:
programme name is ./cmd_arg.sh
first argument is hi
Second argument is this
Total command line arguments is 4
Entered arguments was :hi this is mohan

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>