# What happens when you press Enter in a terminal

> The terminal emulator feeds a shell; Bash forks, execs external commands, waits, and keeps builtins in-process.

Source: https://fullbytedeveloper.com/blog/what-happens-when-you-press-enter
Published here: 2026-12-03, updated 2026-12-03

You type `ls`, press Enter, and a listing appears. Three layers did the work: the terminal emulator, the TTY device, and a shell that parsed the line then ran a built-in or an external program [1] [3]. Related: [pipes and redirection](/blog/pipes-redirection-until-obvious), [essential Linux commands part 1](/blog/essential-linux-commands-developers-part-1).

## Quick start: separate built-in from external

On a draft Linux host with Bash:

```bash
type cd
type ls
```

Output:

```text
cd is a shell builtin
ls is /usr/bin/ls
```

Built-ins live inside the shell process [1]. `ls` resolves to an external file path; Bash will fork and exec for that path [1] [3].

## Draw the Enter key path

<figure aria-label="Path from keyboard through terminal emulator and TTY to shell fork or builtin execution">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 360 340" role="img" aria-hidden="true">
  <defs>
    <marker id="whathappenswhenyoupresse-enter-arr" markerWidth="8" markerHeight="8" refX="7" refY="4" orient="auto">
      <path d="M0,0 L8,4 L0,8 Z" fill="#14b8a6"/>
    </marker>
  </defs>
  <rect x="0" y="0" width="360" height="340" rx="12" fill="#0b1f3a"/>
  <rect x="135.692" y="3.5" width="88.6154" height="45" rx="4" fill="#123052" stroke="#14b8a6" stroke-width="1.38462"/>
  <text x="180" y="31" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">Keyboard</text>
  <line x1="180" y1="44" x2="180" y2="64" stroke="#14b8a6" stroke-width="1.38462" marker-end="url(#whathappenswhenyoupresse-enter-arr)"/>
  <rect x="108" y="63" width="144" height="50" rx="4" fill="#123052" stroke="#14b8a6" stroke-width="1.38462"/>
  <text x="180" y="93" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">Terminal emulator (UI)</text>
  <line x1="180" y1="108" x2="180" y2="128" stroke="#14b8a6" stroke-width="1.38462" marker-end="url(#whathappenswhenyoupresse-enter-arr)"/>
  <rect x="94.1538" y="127" width="171.692" height="50" rx="4" fill="#123052" stroke="#14b8a6" stroke-width="1.38462"/>
  <text x="180" y="157" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">PTY master / slave (TTY)</text>
  <line x1="180" y1="172" x2="180" y2="192" stroke="#14b8a6" stroke-width="1.38462" marker-end="url(#whathappenswhenyoupresse-enter-arr)"/>
  <rect x="101.077" y="191" width="157.846" height="50" rx="4" fill="#123052" stroke="#14b8a6" stroke-width="1.38462"/>
  <text x="180" y="221" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">Bash: parse + expand</text>
  <line x1="138.462" y1="236" x2="83.0769" y2="268" stroke="#14b8a6" stroke-width="1.38462" marker-end="url(#whathappenswhenyoupresse-enter-arr)"/>
  <line x1="221.538" y1="236" x2="276.923" y2="268" stroke="#14b8a6" stroke-width="1.38462" marker-end="url(#whathappenswhenyoupresse-enter-arr)"/>
  <rect x="16.6154" y="265" width="105.231" height="70" rx="4" fill="#123052" stroke="#14b8a6" stroke-width="1.38462"/>
  <text x="69.2308" y="296" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">builtin</text>
  <text x="69.2308" y="314" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">in-shell [1]</text>
  <rect x="238.154" y="265" width="105.231" height="70" rx="4" fill="#123052" stroke="#14b8a6" stroke-width="1.38462"/>
  <text x="290.769" y="292" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">fork, exec</text>
  <text x="290.769" y="310" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">parent wait [2]</text>
</svg>
</figure>

The Bash Beginners Guide: when the first word is a built-in, the shell executes it without creating a new process [1]. External commands use `fork` then replace the child image with `exec`, while the parent waits for status [1] [2].

## Follow fork, exec, wait with real PIDs

```bash
ps -o pid,ppid,cmd -p $$
sleep 2 &
echo "background pid=$!"
wait $!
echo "sleep exit=$?"
```

You should see your shell's PID as `PPID` for a short-lived `sleep` child while it runs, then `wait` returns when that child exits [1] [2]. Background `&` skips the automatic wait; you call `wait` when you need the exit code [1].

The GNU C Library notes that after `fork`, both parent and child continue; collecting child status is explicit via `wait` family calls [2].

## Environment inheritance

Fork copies the parent's environment, open file descriptors, and working directory into the child before `exec` replaces the program [1] [2]. That is why `export` affects children and why redirection on the shell line applies before the program starts.

```bash
export DEMO_FBD=1
env | grep DEMO_FBD
```

Draft host output:

```text
DEMO_FBD=1
```

The child `env` process inherited the variable [1] [2].

## Parsing before execution

Per the Beginners Guide, Bash tokenizes the line, performs expansions (parameters, globs, command substitution), then applies redirections and pipes [1]. Pipes are not magic shortcuts; they wire file descriptors between processes. Detail: [pipes and redirection](/blog/pipes-redirection-until-obvious).

Command substitution `$(...)` runs a nested shell or command and substitutes stdout text into the outer line before the final execution pass [1].

## Job control symbols

`&` runs a command in the background. `fg` and `bg` move jobs; `jobs` lists them [3]. Each external job is still a process with its own PID [2]. Signals interact with process groups; see [Ctrl+C is SIGINT](/blog/ctrl-c-is-sigint) for the interrupt path.

## SSH and remote terminals

SSH allocates a PTY on the server when you pass `-t` or when sshd forces one for interactive sessions. The same Bash fork/exec story runs; only the emulator moves to your local laptop window.

## What the terminal emulator actually does

The emulator translates key events into bytes on the PTY master side [3]. Control keys generate control characters; Enter typically inserts a newline the shell reads as end-of-line. The shell does not see pixels; it sees a byte stream. Resizing the window sends `SIGWINCH` so full-screen programs can reflow.

Line editing (`readline` behavior) happens in the shell before execution: history, `Ctrl+A`, and completion are shell features, not the terminal binary.

## Subshells and grouping

Parentheses `( ... )` run commands in a subshell: another Bash instance that inherits copies of variables unless exported [3]. Pipes may run the right-hand side in a subshell depending on shell options; that detail bites when you try to mutate variables inside pipelines.

## One line, multiple commands

`;` runs sequentially. `&&` and `||` gate on exit status [3]. Each external segment in the chain can fork separately. Built-ins in the chain still avoid extra processes [1].

## Mistakes that waste a week

Calling Terminal.app or Windows Terminal "Bash." The emulator is not the shell [3].

Expecting `cd` to fork (it does not; it mutates the shell's working directory) [1].

Background jobs always inherit your script's `set -e` behavior across subshell boundaries.

Forgetting that `exec` replaces the child without returning when successful [2].

Pipes do not create threads. They create processes (or built-in combos) with connected file descriptors [1]. They create processes (or built-in combos) with connected file descriptors [1].

Running `sudo command` and not realizing a new user context and often a new environment contract apply.

## Aliases and functions before fork

Bash expands aliases before deciding built-in versus external [3]. A function defined in the shell also runs without `exec` unless it calls an external explicitly. `type` and `command -v` are your truth serum when a script behaves differently from an interactive session.

## Exit codes propagate

The exit status of the last foreground command becomes `$?` [1]. `set -e` in scripts makes the shell exit on failure unless guarded. Pipelines with `set -o pipefail` surface failures in middle stages [3]. These rules sit entirely in the shell layer before your program's own exit codes.

## Interactive vs non-interactive shells

Bash reads startup files differently when stdin is a TTY versus a script [3]. An interactive login shell loads profiles you never see in CI. That distinction explains why aliases work on your laptop but not in `cron` unless you define them in the script.

## Heredocs and multiline input

Heredocs supply multiple lines to a command without a separate file [3]. The shell still parses the delimiter line before running the compound command, so redirection and variable expansion follow the same order as single-line input [1].

When you paste a multiline block into an interactive session, each line waits for Enter until the shell decides the compound command is complete.

Tab completion and history search stay in readline until you accept a line [3].

Wrappers such as `nice`, `env`, and `time` may exec another program while remaining parent processes; `type` shows whether the wrapper is external [1] [3].

A remote `ssh host command` often skips aliases you rely on interactively, so scripts should use absolute paths or export what they need [3].

Here-strings, pipes, and `/dev/null` only change which descriptors the child inherits; the fork/exec path is the same [1].

Tonight, run `type ls`, `type cd`, and `type echo` and write down which ones never `fork`. That list is the whole lesson in one sticky note. When you need process IDs and credentials behind the child that did fork, read what is a process; for shared-memory concurrency versus isolation, continue with [threads vs processes](/blog/threads-vs-processes).

Send this to the friend who thinks every command forks a new process.

Image: Abstract illustration of a signal moving across raised platforms with teal disks, an orange ringed gate, and a U-shaped return arrow beside a faint app-window outline, no people and no readable UI text.
https://fullbytedeveloper.com/media/what-happens-when-you-press-enter/what-happens-when-you-press-enter-venice.webp
Enter crosses layers: gate, central platform, then a child path with a return loop.

## Sources

1. [Bash Guide for Beginners (TLDP), executing commands, accessed 2026-12-03](https://tldp.org/LDP/Bash-Beginners-Guide/html/sect_01_03.html)
2. [GNU C Library: Process Creation Concepts, accessed 2026-12-03](https://www.sourceware.org/glibc/manual/latest/html_node/Process-Creation-Concepts.html)
3. [GNU Bash manual (HTML), accessed 2026-12-03](https://www.gnu.org/software/bash/manual/bash.html)
4. [Full Byte Developer: Pipes and redirection until they feel obvious](https://fullbytedeveloper.com/blog/pipes-redirection-until-obvious)
5. [Full Byte Developer: Essential Linux commands part 1](https://fullbytedeveloper.com/blog/essential-linux-commands-developers-part-1)
6. [Full Byte Developer: Ctrl+C is SIGINT](https://fullbytedeveloper.com/blog/ctrl-c-is-sigint)
