This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the bash category.
Last Updated: 2024-11-21
I encounted this code in a Dockerfile entrypoint bash script. What is the usual purpose of such code?
if [ -z "$1" ]; then
# do something
fi
Technically, this checks if $1
is empty. And why does that matter? Because, in effect, this checks if there are 0 arguments to the script. This can be used for validating input arguments or for taking alternate actions depending on argument count.