Skip to content

Commit 852df7c

Browse files
authored
Merge pull request #17849 from oluG4real/command-line-arguments
Command line arguments - retest
2 parents 6ff34bf + da84a6e commit 852df7c

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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";

0 commit comments

Comments
 (0)