File tree 2 files changed +29
-0
lines changed
linux-bash-modules/command-line-arguments/src/main/bash
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ while getopts u:a:f: flag
3
+ do
4
+ case " ${flag} " in
5
+ u) username=${OPTARG} ;;
6
+ a) age=${OPTARG} ;;
7
+ f) fullname=${OPTARG} ;;
8
+ esac
9
+ done
10
+ # Now handle positional arguments
11
+ shift $(( OPTIND - 1 ))
12
+ param1=$1 # First positional argument
13
+ param2=$2 # Second positional argument
14
+ param3=$3 # Third positional argument
15
+ echo " Username: $username " ;
16
+ echo " Age: $age " ;
17
+ echo " Full Name: $fullname " ;
18
+ echo " First Positional Parameter: $param1 " ;
19
+ echo " Second Positional Parameter: $param2 " ;
20
+ echo " Third Positional Parameter: $param3 " ;
Original file line number Diff line number Diff line change
1
+ # Argument validation check
2
+ if [ " $# " -ne 3 ]; then
3
+ echo " Usage: $0 <username> <age> <fullname>"
4
+ exit 1
5
+ fi
6
+ # The Positional Parameters
7
+ echo " Username: $1 " ;
8
+ echo " Age: $2 " ;
9
+ echo " Full Name: $3 " ;
You can’t perform that action at this time.
0 commit comments