forked from gautamjha2002/Bash_Scripting
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16_Options_in_Bash.sh
More file actions
executable file
·31 lines (21 loc) · 910 Bytes
/
Copy path16_Options_in_Bash.sh
File metadata and controls
executable file
·31 lines (21 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env bash
# In addition to pass information to a script using argument, we can also specify options.
# Options allow us to pass information into a script from the calling
# options are a combination of a dash and a letter (like -u or -p)
# optons are accessed using the getops keyword
# Options can take arguments of their own
# Options can be specified and used in any order.
# Example :- Let's say we want to make a script that accepts a username and password
# We can use arguments for this but then we need to make sure that the username and password were entered in a certain order.
# to make this eaiser we can use options.
# Example :-
while getopts u:p: option; do
case $option in
u) user=$OPTARG;;
p) pass=$OPTARG;;
esac
done
echo "user: $user / pass: $pass"
# now we can give input using -u and -p
# -u is for username
# -p is for passowrd