This article will show you how to use command-line arguments in your script in Bash.
In Bash, we can use arguments that were passed as parameters of our script. We can refer to them using $1 (first parameter), $2 (second argument), etc.
#!/bin/bash echo $1 echo $2 echo $3
After calling the script by:
$ ./my_script.sh one two three
The output is:
one two three
Go through all given arguments
#!/bin/bash for parameter in "$@" do echo $parameter done
Calling the script:
$ ./my_script.sh one two three four
one two three four