Bash argument set

Check if a bash argument is set in a script

File varcheck.sh

#!/usr/bin/env bash

if [ -z ${1+x} ]; then
    echo "var is unset";
else
    echo "var is set to '$1'";
fi

varcheck.sh will output: var is unset varcheck.sh TADA will output: var is set to 'TADA'

Leave a Reply

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