bash parameter count 1

bash parameter count

# use $#

# say if you are expecting exactly 2 parameters
# -ne is bash's way of saying not equal
if [[ "$#" -ne 2 ]]; then
	echo "this script needs exactly 2 parameters"
    exit 1

Here is what the above code is Doing:
1. It’s checking if the number of parameters is not equal to 2.
2. If it is not equal to 2, it prints a message and exits.
3. If it is equal to 2, it continues on.

Similar Posts