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.
Example my_script.sh
file:
xxxxxxxxxx
1
2
3
echo "$1"
4
echo "$2"
5
echo "$3"
Run in command line:
xxxxxxxxxx
1
./my_script.sh one two three
Output:
xxxxxxxxxx
1
one
2
two
3
three
Example my_script.sh
file:
xxxxxxxxxx
1
2
3
for parameter in "$@"
4
do
5
echo "$parameter"
6
done
Run in command line:
xxxxxxxxxx
1
./my_script.sh one two three four
Output:
xxxxxxxxxx
1
one
2
two
3
three
4
four