WHILE(1) fish-shell WHILE(1)

# [NAME](#NAME)

while - perform a set of commands multiple times

# [SYNOPSIS](#SYNOPSIS)

```
while CONDITION; COMMANDS; end
```

# [DESCRIPTION](#DESCRIPTION)

**while** repeatedly executes **CONDITION**, and if the exit status is 0, then executes **COMMANDS**.

The exit status of the **while** loop is the exit status of the last iteration of the **COMMANDS** executed, or 0 if none were executed. (This matches other shells and is POSIX-compatible.)

You can use and &lt;&gt; or or &lt;&gt; for complex conditions. Even more complex control can be achieved with **while true** containing a break &lt;&gt;.

The **-h** or **--help** option displays help about using this command.

# [EXAMPLE](#EXAMPLE)

```
while test -f foo.txt; or test -f bar.txt ; echo file exists; sleep 10; end
# outputs 'file exists' at 10 second intervals,
# as long as the file foo.txt or bar.txt exists.
```

# [Copyright](#Copyright)

fish-shell developers

October 12, 2026 4.9

---

Document: while(1) from fish 4.9.3-r2 (Chainguard OS)
Source: https://github.com/fish-shell/fish-shell
