File: while.rst

package info (click to toggle)
fish 4.2.1-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,980 kB
  • sloc: python: 6,972; javascript: 1,407; sh: 1,009; xml: 411; ansic: 230; objc: 78; makefile: 20
file content (30 lines) | stat: -rw-r--r-- 937 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
while - perform a set of commands multiple times
================================================

Synopsis
--------

.. synopsis::

    while CONDITION; COMMANDS; end

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 :doc:`and <and>` or :doc:`or <or>` for complex conditions. Even more complex control can be achieved with ``while true`` containing a :doc:`break <break>`.

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

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.