Átomo
61If
Ambiente e scripts · Linux / macOS

if / test

Abrir na tabela

Definição

Condições em scripts. [ ] ou [[ ]] testam arquivos, strings e números.

Exemplos

1. Arquivo existe
if [ -f sales.csv ]; then
  echo "found"
else
  echo "missing"
fi
2. Comparações
if [[ "$env" == "prod" && $rows -gt 0 ]]; then
  echo "ok"
fi
3. Em uma linha
[ -d data/ ] || mkdir data
test -z "$TOKEN" && echo "no token"

No mesmo grupo