Pages

06 September, 2023

bash: How to check if variable exists when set -eu option is set

In one of my prod script set -eu is set. In this script I want to check if variable exists but -v and -z option is not working. #!/bin/bash set -eu set -o pipefail INTERNAL="sdkhf" if [ -v $IINTERNAL ] then echo "variable doesnt exists" else echo "variable exists" fi output ./script.sh: line 7: IINTERNAL: unbound variable Is there a way to check for variable if it doesnt exist, dont go inside if loop.

No comments:

Post a Comment

Thanks