Bash script arguments example

In this post, I will shortly share Bash script arguments via an easy example so it can help you understand how it works and write a bash script with parameters input from command line in terminal.

Let’s imagine the following command line:

If your_bash_program were a bash shell script, we could read each item on the command line because the positional parameters contain the following:

  • $0 would contain “your_bash_program
  • $1 would contain “word1”
  • $2 would contain “word2”
  • $3 would contain “word3”

Here is a script you can use to try this out:

Also published on Medium.

Leave a Reply

Notify of