BAEL-3469 - How to Pass command line arguments to bash script

This commit is contained in:
Radhe Sravan 2019-11-10 09:15:18 +05:30
parent 21ecb354d9
commit 595649bf05
4 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,14 @@
#!/bin/bash
while getopts u:a:f: flag
do
case "${flag}"
in
u) username=${OPTARG};;
a) age=${OPTARG};;
f) fullname=${OPTARG};;
esac
done
echo "Username: $username";
echo "Age: $age";
echo "Full Name: $fullname";

View File

@ -0,0 +1,5 @@
#!/bin/bash
echo "Username: $1";
echo "Age: $2";
echo "Full Name: $3";

View File

@ -0,0 +1,8 @@
#!/bin/bash
i=1;
for user in "$@"
do
echo "Username - $i: $user";
i=$((i + 1));
done

View File

@ -0,0 +1,10 @@
#!/bin/bash
i=1;
j=$#;
while [ $i -le $j ]
do
echo "Username - $i: $1";
i=$((i + 1));
shift 1;
done