Languages
[Edit]
EN

Bash - how to use command line arguments in script

3 points
Created by:
martineau
1350

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

Edit

Example my_script.sh file:

Run in command line:

Output:

Go through all given arguments

Edit

Example my_script.sh file:

Run in command line:

Output: 

 

Alternative titles

  1. Bash - pass argument as variable to script file
  2. Bash - pass argument as variable into script.sh file
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Bash

Bash - how to use command line arguments in script
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join