True (Unix)
From Wikipedia, the free encyclopedia
- The correct title of this article is true (Unix). The initial letter is shown capitalized due to technical restrictions.
In Unix-like operating systems, true is a command whose only function is to always return the value 0, which is regarded by the shell as the logical value true. It is usually employed in conditional statements and loops of shell scripts where Boolean conditions are given as the return value of a program. For example, the following bash script echos the string hello
until interrupted:
while true; do echo hello done
This program takes no "actual" parameters; in some versions, the standard parameter --help
displays a usage summary and --version
displays the program version.
true
may also be written as a single colon (:
). In that form, it is generally built into the shell, and may therefore be more efficient.
In its alias of :
, true
is often used (in POSIX-compatible shells such as the Bourne shell) as a dummy command when assigning default values to shell variables through the ${parameter:=word}
parameter expansion form.[1] For example, from bashbug, the bug-reporting script for bash:
: ${TMPDIR:=/tmp} : ${EDITOR=$DEFEDITOR} : ${USER=${LOGNAME-`whoami`}}
[edit] References
- ^ Shell Command Language: 2.6.2 Parameter Expansion – The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
[edit] See also
Unix command line programs and builtins (more) | |||
File and file system management: | cat | chattr | cd | chmod | chown | chgrp | cp | du | df | file | fsck | ln | ls | lsof | mkdir | mount | mv | pwd | rm | rmdir | split | touch | ||
Process management: | at | chroot | crontab | exit | kill | killall | nice | pgrep | pidof | pkill | ps | sleep | time | top | wait | watch | ||
User Management/Environment: | env | finger | id | mesg | passwd | su | sudo | uname | uptime | w | wall | who | whoami | write | ||
Text processing: | awk | comm | cut | ex | head | iconv | join | less | more | paste | sed | sort | tail | tr | uniq | wc | xargs | ||
Shell programming: | echo | expr | printf | unset | Printing: | lp |
Communications: inetd | netstat | ping | rlogin | traceroute |
Searching: find | grep | strings |
Miscellaneous: banner | bc | cal | man | size | yes |