Skip to content
The Bash Insectarium

/static/insetario/en/inseto/param-erro/

Menu

BSH-006 · Parameters

${var:?erro}

No value, and the script stops right there — with the message you chose.

The family's sentinel: if var is empty or absent, the shell writes the message to standard error and, in a script, exits on the spot. No rm -r departs with an empty destination.

It is the cheapest precondition check there is: one line, no if. In an interactive shell the command is aborted, but the session survives.

$ unset DESTINO
$ cp coleta.db "${DESTINO:?defina DESTINO antes}"
bash: DESTINO: defina DESTINO antes
$ echo $?
1
The empty variable, stopped at the door.