ArticleslgStudy

science

True and false (commands)

True and false (commands) is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand True and false (commands) rather than just read about it. In short: true and false are shell commands that exit immediately with exit status 0 or 1, respectively. As a script sets its process exit status to the value of the last command it runs, these commands can be used to set the exit status of a script run.

Key takeaways

  • True and false (commands) belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect True and false (commands) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of True and false (commands) from memory before moving on to harder problems.

Reference excerpt

true and false are shell commands that exit immediately with exit status 0 or 1, respectively. As a script sets its process exit status to the value of the last command it runs, these commands can be used to set the exit status of a script run. All Unix shells interpret an exit status of zero as success and non-zero (usually) as failure, so true sets success and false sets failure. The commands are available in Unix-like operating systems.

Use The commands are usually employed in conditional statements and loops of shell scripts. For example, the following script repeatedly executes echo hello until interrupted:

The commands can be used to ignore the success or failure of a sequence of other commands, as in the example:

Setting a user's login shell to false, in /etc/passwd, effectively denies them access to an interactive shell, but their account may still be valid for other services, such as FTP. (Although /sbin/nologin, if available, may be more fitting for this purpose, as it prints a notification before terminating the session.) The programs accept no command-line arguments except that the GNU version accepts the typical --help and --version options.

Null command The true command is sometimes substituted with the very similar null command, written as a single colon (:). The null command is built into the shell, and may therefore be more efficient if true is an external program (true is usually a shell built in function). We can rewrite the upper example using : instead of true:

The null command may take parameters, which are ignored. It is also used as a no-op dummy command for side-effects such as assigning default values to shell variables through the ${parameter:=word} parameter expansion form. For example, from bashbug, the bug-reporting script for Bash:

Null smileys Either true or : can be used as a replacement for cat /dev/null, so there are 3 "null smileys":

:> - create a file or empty it if it already exists; :>> - create a file if it doesn't exist, unlike touch it does not change the timestamp of existing file; :| - can be used instead of < /dev/null Such usage is similar to the IEFBR14's standard usage.

See also IEFBR14 – "Do nothing" program on IBM mainframes List of POSIX commands Two-valued logic – Classical logic of two values, either true or falsePages displaying short descriptions of redirect targets

Notes

References

External links

true: return true value – Shell and Utilities Reference, The Single UNIX Specification, Version 5 from The Open Group false: return false value – Shell and Utilities Reference, The Single UNIX Specification, Version 5 from The Open Group

Manual pages true(1): Do nothing, successfully – GNU Coreutils reference false(1): Do nothing, unsuccessfully – GNU Coreutils reference true(1): Return true value – FreeBSD manual page false(1): Return false value – FreeBSD manual page

Worked examples

Example 1 — a first encounter with True and false (commands)

Start with the simplest possible case. Write down what True and false (commands) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to True and false (commands) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about True and false (commands) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of True and false (commands)

In research
True and false (commands) appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses True and false (commands) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
True and false (commands) is common in secondary-school and first-year university syllabi. It links to neighbouring topics IBM i Qshell commands, Standard Unix programs, Unix SUS2008 utilities, so understanding it makes those chapters shorter.
In everyday life
Look for True and false (commands) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “True and false (commands)” →

How to study True and false (commands) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what True and false (commands) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain True and false (commands) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is True and false (commands) in simple terms?

true and false are shell commands that exit immediately with exit status 0 or 1, respectively. As a script sets its process exit status to the value of the last command it runs, these commands can be used to set the exit status of a script run.

Why does True and false (commands) matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study True and false (commands)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on True and false (commands).

Tags

  • IBM i Qshell commands
  • Standard Unix programs
  • Unix SUS2008 utilities

Keep exploring