Bash Script with Arguments

Bash Script with Arguments

Bash Script

Have you ever wondered to input the arguments in the bash scripts. Well there is the process how you do it.

Step 1: add the following script on the top of bash script file (test.sh)

# passing the arguments

while [ $# -gt 0 ]; do

if [[ $1 == *"--"* ]]; then

        v="${1/--/}"

declare $v="$2"

fi

shift

done

 

echo $appName $version # this one is passed as an arguments

Step 2: pass the name of variable that you want to access in as an arguments something like this

./test.sh –-appName App1 –-version v1.2

 

What a great way isn’t it?

2 thoughts on “Bash Script with Arguments

Leave a Reply to admin Cancel reply

Your email address will not be published. Required fields are marked *

How to whitelist website on AdBlocker?

How to whitelist website on AdBlocker?

  1. 1 Click on the AdBlock Plus icon on the top right corner of your browser
  2. 2 Click on "Enabled on this site" from the AdBlock Plus option
  3. 3 Refresh the page and start browsing the site
%d bloggers like this: