# O Que É uma Linha Shebang? Escolhendo o Interpretador

> Uma linha shebang é a primeira linha de um script que informa ao SO com qual interpretador executá-lo. Saiba como shebangs funcionam e por que importam para scripts de CI.

Source: https://latchkey.dev/pt/learn/ci-explained/what-is-a-shebang-line  
Updated: 2026-06-26

Uma linha shebang é a primeira linha de um script, iniciando com #! , que informa ao sistema operacional qual interpretador deve executar o arquivo.

Quando você executa um script diretamente, o sistema operacional precisa saber qual programa deve interpretá-lo: Bash, Python, Node ou algo mais. A linha shebang responde isso. É um detalhe pequeno mas importante que decide qual shell ou interpretador, e portanto quais recursos, seu script de CI recebe.

## Como um shebang se parece

É a primeira linha e começa com os dois caracteres #! seguidos de um caminho, por exemplo `#!/bin/bash` ou `#!/usr/bin/env python3`. O SO o lê quando você executa o arquivo diretamente.

## Como é usado

Quando você executa `./script.sh`, o kernel vê o shebang, lança o interpretador nomeado e passa o arquivo a ele. Sem um shebang, o SO pode recair no shell padrão, que talvez não seja o que você pretendia.

## Shebangs baseados em env

- `#!/bin/bash` aponta para um caminho fixo do Bash.
- `#!/usr/bin/env bash` encontra o Bash via PATH, o que é mais portável.
- `#!/usr/bin/env python3` faz o mesmo para interpretadores Python.

## Por que o shebang importa

O shebang decide se seu script roda sob `sh` ou `bash`, o que muda quais recursos estão disponíveis. Um script que usa arrays do Bash vai quebrar se seu shebang resolver para um shell POSIX puro.

## Shebangs em CI

CI frequentemente invoca scripts explicitamente (`bash deploy.sh`), o que sobrepõe o shebang. Mas quando steps chamam um script versionado diretamente, o shebang controla o interpretador, então acertá-lo mantém execuções locais e de CI consistentes.

## Consistência em runners gerenciados

Os runners da Latchkey fornecem os interpretadores em localizações previsíveis, então um shebang `#!/usr/bin/env bash` resolve da mesma forma a cada execução. Isso mantém scripts executados diretamente se comportando igual no CI e na máquina de um desenvolvedor.

## Applying this to your pipeline

- Measure before changing. Most CI optimisation targets the wrong step because the slow one is assumed rather than timed.
- Cache what is expensive to produce and cheap to validate, and key the cache to the exact tool version.
- Fail fast: run the cheapest checks that can reject a change first, so an expensive job never starts on code that cannot pass.
- Prefer determinism over speed when they conflict. A fast pipeline nobody trusts gets re-run, which is slower than a slow one that is believed.

## FAQ

### What is What is a shebang Line? choosing the interpreter?

When you run a script directly, the operating system needs to know what program should interpret it: Bash, Python, Node, or something else. The shebang line answers that. It is a small but important detail that decides which shell or interpreter, and therefore which features, your CI script gets.

### What a shebang looks like?

It is the very first line and begins with the two characters #! followed by a path, for example #!/bin/bash or #!/usr/bin/env python3. The OS reads it when you execute the file directly.

### How it is used?

When you run ./script.sh, the kernel sees the shebang, launches the named interpreter, and hands it the file. Without a shebang, the OS may fall back to the default shell, which might not be what you intended.

### Why the shebang matters?

The shebang decides whether your script runs under sh or bash, which changes which features are available. A script using Bash arrays will break if its shebang resolves to a plain POSIX shell.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
