Notes, code snippets for Bash.
Is argument set or empty string.
function isEmpty() {
local target=$1
if [ -z "$target" -a "${target+xxx}" = "xxx" ]; then
echo true
else
echo false
fi
}
foo="bar"
isEmpty $foo # --> false
foo=""
isEmpty $foo # --> true
# Do something for arg 'a' and 'b'.
# Ex: $ bash [my-file.sh] -a hello -b world
# --> hello
# --> world
while getopts ":a:b:" opt; do
case ${opt} in
a )
target=$OPTARG
echo $target
;;
b )
target=$OPTARG
echo $target
;;
\? )
echo "Invalid option: $OPTARG" 1>&2
;;
: )
echo "Invalid option: $OPTARG requires an argument" 1>&2
;;
esac
done
shift $((OPTIND -1))