How to check if a shell script received any arguments

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the bash category.

Last Updated: 2023-03-28

I encounted this code in a Dockerfile entrypoint bash script. What is the usual purpose of such code?

if [ -z "$1" ]; then
  # do something 

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.