Passing Arguments to the Bash Script
Passing Arguments to the Bash Script
Today we will be looking at how to parse the arguments to the bash script
If you want to know more stuff about bash scripting you can visit Bash Scripting Tutorial
List of Contents
- Example of argument passing
- Parsing the Arguments
Example of argument passing
Suppose consider we are 'updating' our system, we use the command apt update then you can see the apt as the file & update as the argument we have passed to the file or command.
Parsing the Arguments
The arguments are stored in a variable from $1 - $9
- bash bash_script.sh LetsConfigure ( the LetsConfigure is the argument passed to the bash Script )
You can also give other arguments also with the consecutive numbers
- $$ - Give the Process ID
- $0 - Gives the file name
- $# - Gives the number of arguments passed to the script
- $* - Give all the arguments passed
- $@ - Gives the value to an array
Note:-
If you put the arguments in the quotes, then it is considered a single argument.
There are some other arguments in the Bash Scripting you can give, we will cover that in our later tutorials as we get to know the bash script more & more.
Conclusion:-
We have learned to pass the arguments to the bash script & different types of variables in the bash scripting.