EN
Bash - how to use command line arguments in script
3
points
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), "$3"
(third argument), etc.
Practical example
Example my_script.sh
file:
#!/bin/bash
echo "$1"
echo "$2"
echo "$3"
Run in command line:
./my_script.sh one two three
Output:
one
two
three
Go through all given arguments
Example my_script.sh
file:
#!/bin/bash
for parameter in "$@"
do
echo "$parameter"
done
Run in command line:
./my_script.sh one two three four
Output:
one
two
three
four