November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

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>