Passing arguments in command line to bash

If you want to run a bash script and set the values to be evaluated at the same time, you can use $1 or $2 etc (for first, second, and so on) for your variables and strings. An example Script is below.

┌─[feoleb@godzilla]─[~/scripting_lab]
└──╼ $cat string_ops.sh
#!/bin/bash

if [ "$1" = "Hello" ]
then
	echo "First argument is equal to Hello"
else 
	echo "First argument is not equal to Hello"
fi

if [ "$1" = "Good bye" ]
then
	echo "First argument is equal to Good bye"
else 
	echo "First argument is not equal to Good bye"
fi

if [ -z "$1" ]
then 
	echo "First argument is null"
else 
	echo "First argument is not null"
fi

if [ -z "$2" ]
then
	echo "Second argument does not exist"
else 
	echo "Second argument exists"
fi

If I run the following command from the command prompt you can see how it works

┌─[feoleb@godzilla]─[~/scripting_lab]
└──╼ $sh string_ops.sh Hello Goose
First argument is equal to Hello
First argument is not equal to Good bye
First argument is not null
Second argument exists

If I wanted to include the possibility for a third argument, I would have to add $3 in the code.