Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 Usage  





2 Null command  





3 See also  





4 Notes  





5 References  





6 External links  



6.1  Manual pages  
















true and false (commands)






العربية
Čeština
Ελληνικά
Español

Tiếng Vit

 

Edit links
 









Article
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Cite this page
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 


true
Initial releaseJanuary 1979; 45 years ago (1979-01)
Operating systemUnix and Unix-like
PlatformCross-platform
TypeCommand

InUnix-like operating systems, true and false are commands whose only function is to always return with a predetermined exit status. Programmers and scripts often use the exit status of a command to assess success (exit status zero) or failure (non-zero) of the command. The true and false commands represent the logical values of command success, because true returns 0, and false returns 1.[Note 1]

Usage[edit]

The commands are usually employed in conditional statements and loopsofshell scripts. For example, the following shell script repeats the echo hello loop until interrupted:

while true
do
  echo hello
done

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

make  && false

Setting a user's login shelltofalse, 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 take no "actual" parameters; in the GNU version, the standard parameter --help displays a usage summary and --version displays the program version.

Null command[edit]

The true command is sometimes substituted with the very similar null command,[1] 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:

while :
do
  echo hello
done

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.[2] For example, from bashbug, the bug-reporting script for Bash:

 : ${TMPDIR:=/tmp}
 : ${EDITOR=$DEFEDITOR}
 : ${USER=${LOGNAME-`whoami`}}

See also[edit]

Notes[edit]

  1. ^ These are distinct from the truth valuesofclassical logic and most general purpose programming languages: true (1 or T) and false (0 or ⊥).

References[edit]

  1. ^ "Colon", The Open group base specifications, issue 7, IEEE std 1003.1-2008
  • ^ Cooper, Mendel (April 2011), "Null command", Advanced Bash-scripting guide, 6.3, The Linux documentation project, retrieved 2011-08-04
  • External links[edit]

    Manual pages[edit]


    Retrieved from "https://en.wikipedia.org/w/index.php?title=True_and_false_(commands)&oldid=1197776418"

    Categories: 
    Standard Unix programs
    Unix SUS2008 utilities
    IBM i Qshell commands
    Hidden categories: 
    Articles with short description
    Short description is different from Wikidata
     



    This page was last edited on 21 January 2024, at 22:21 (UTC).

    Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



    Privacy policy

    About Wikipedia

    Disclaimers

    Contact Wikipedia

    Code of Conduct

    Developers

    Statistics

    Cookie statement

    Mobile view



    Wikimedia Foundation
    Powered by MediaWiki