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:
[[email protected] me]$ your_bash_program word1 word2 word3
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:
#!/bin/bash echo "List Parameters" echo '$0 = ' $0 echo '$1 = ' $1 echo '$2 = ' $2 echo '$3 = ' $3
Latest posts by admin (see all)
- Install and Running Supervisord in virtualenv python 2.7 - January 24, 2019
- Urgent fix: Briefly unavailable for scheduled maintenance. Check back in a minute. - January 22, 2019
- Change WordPress post date format to time ago - January 21, 2019
Also published on Medium.