Intro To 'true' Command In Linux
2023-05-20 - By Robert Elder
I use the 'true' command which does absolutely nothing and then exits successfully:
true
The 'true' command can be built into the shell or it can exist as a regular executable:
type -a true
true is a shell builtin
true is /usr/bin/true
true is /bin/true
Return Code 0 == 'Success'
Just like many other commands, whenever you run the 'true' command it will exit with a successful return code:
true
You can verify this by echoing the dollar sign question mark variable and then observing the value of 0 which indicates a successful program exit:
echo $?
0
Use Case Of 'true' Command
The 'true' command is useful whenever you must specify a program that should exit successfully. Here is a while loop that will print hello world forever:
while /bin/true; do echo 'Hello World!'; sleep 1; done
And the output will look like this:
Hello World!
Hello World!
Hello World!
Hello World!
... Message repeated every 1 second forever.
The 'while' keyword in bash will continue to run the loop as long as the command exits successfully, and that's exactly what the 'true' command always does.
That's why the 'true' command is my favourite Linux command.
![]() A Surprisingly Common Mistake Involving Wildcards & The Find Command
Published 2020-01-21 |
![]() $20.00 CAD |
![]() A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
Published 2019-08-01 |
![]() The Most Confusing Grep Mistakes I've Ever Made
Published 2020-11-02 |
![]() Use The 'tail' Command To Monitor Everything
Published 2021-04-08 |
![]() Using A Piece Of Paper As A Display Terminal - ed Vs. vim
Published 2020-10-05 |
![]() An Introduction To Data Science On The Linux Command Line
Published 2019-10-16 |
![]() An Overview of How to Do Everything with Raspberry Pi Cameras
Published 2019-05-28 |
Join My Mailing List Privacy Policy |
Why Bother Subscribing?
|