Handling empty variables safely
If a user forgets to provide an argument, a variable might end up empty. If your script runs something like rm -rf “$TARGET_DIR/” and $TARGET_DIR is blank, the shell evaluates it as rm -rf /, which will attempt to wipe your entire system.
# Syntax: ${variable:-default_value}
# If $1 is empty, target defaults to "guest_user"
target="${1:-guest_user}"
# Syntax: ${variable:?error_message}
# If $1 is empty, the script exits immediately with the error message
target_dir="${1:?Error: You must provide a target directory!}"