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

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

%d bloggers like this: