Passing arguments to the main program when it start is know as command line arguments
In shell scripting arguments can be described like below
$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 sujin
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 sujin
No comments:
Post a Comment