- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
I am much more interested in the story behind this, just like with every sign, every check has a failure that led to its creation.
Admin
I also like the bad grammar, and tying it all in to the laws of physics.
Admin
Perhaps some distros don't include the 'true' command?
Admin
Maybe this is a test where one can prove to be sane by calling this out, and removing it? No one has yet to pass...
Admin
Could be an attempt to protect against being run on systems that don't use zero for success? Not to actually work on those systems, just to prevent it from trying to run and producing weird results. man 3 exit says:
Now, I don't know if bash runs on VMS, and if it does, it might well translate exit statuses to the Unix convention, but the author of the code might not have thought of that.
(It also makes the "exit 1" rather suspect, but again, the author might not have thought it through entirely.)
Admin
Just tested this on Cygwin, apparently it's not installed by default, and ${?} gives 127
Admin
That's in reference to a return from a C main(). And it's only half correct. Of course (of course!) the bit that's correct is the bit that doesn't apply here: it's true that EXIT_FAILURE is more portable than a semi-random non-zero value, but a return value of zero must indicate success, VMS be hanged.
Admin
Yep, that'd be my bet... I'd guess that the script author encountered one of those systems by chance, and started writing ultra-defensive code to detect it (probably copy-pasted into all future scripts).
Admin
If true returns 1 wouldn't then the -ne in the if also possibly return 0 if they are not equal. This means that it would pass sanity check
Admin
The reference to the fundamental laws of nature reads like an exaggeration, but there are a few more variables here:
I disagree with calling those conventions "laws of physics" on the ground of free will, but maybe the contributor is a hardcore Laplacian determinist.
Admin
I'd like to see these "microcontrollers" that Remy claims are running bash. Microntroller != embedded Microprocessor.
Remy says: the bash scripts are for deploying code to microcontrollers
Admin
I'd like to see where the article claims that bash is running on the microcontroller itself.
Admin
Since the shebang uses /usr/bin/env bash, it finds whatever version of bash is in the user's $PATH. Maybe it's trying to detect a bogus version of bash in the user's search path (maybe he's made the mistake of having "." in his path). Although reporting that as a failure of the laws of nature seems to be a bit of an exxageration.
Admin
This is an OLD convention of testing that RAM images aren't corrupt. And "OLD" means from the 70s. I also have seen this used to prevent running on the "wrong" UNIX because on some, yes and true return 1 but no and false return 0.
Y'know.... cuz using "uname" is too much trouble.
Admin
You must be one of those browser sniffing over feature detection aficionados.
Admin
Checkmate.
Admin
Nope. https://www.screencast.com/t/krP2LlnKn
I get a return of zero.
Addendum 2018-06-18 15:28: EDIT: I think this is because bash parsed the entire line before executing the alias statement. Subsequent invocations of "true" returned 1. Only this first one returned zero.
Admin
For all those who claim that bash can't be run on a microcontroller, I hereby present Linux running on an 8-bit ATmega1284p: http://dmitry.gr/?r=05.Projects&proj=07.%20Linux%20on%208bit
Admin
Just use a function:
true() { return 42; }; true; echo $?
Admin
Derp. Aliases also apparently don't work from inside shell scripts. So going with a function like siciac suggested is the way to go.
Admin
ifor some reason, this old story came to mind: https://thedailywtf.com/articles/a-shining-perl
Admin
TIL about the program "true". I didn't know about it before. I use IBM JCL, and it has a program that returns true as well. But in keeping with IBM sensibility, it is named: IEFBR14
Put that in your script and smoke it.
Admin
Re: IBM JCL...
The program IEFBR14 in the beginning only 'returned' since the callers address was left in register 14 when the program started. The register that contained the return code (R0?) was whatever was there when the routine was called. In later versions, the register that had the return code was set to zero, but that was a later addition.
Most of the time this routine was used because what you wanted was the after effects of the JCL, like delete the "dataset" (AKA file), or allocate it on secondary storage (blocking factors, etc.).
Please remember, this was all invented in the 60's, which for many of us was a while ago (ancient history?).
Admin
@Remy: Why wouldn't you have your CM build the product using microcontrollers that have been pre-programmed with your released code? Most distributors provide this value-add service. Much more efficient than loading code at product test cycle.
Admin
Chesterton's Fence (as evidenced by a couple of cromulent suggestions already made.)
I'm more interested as to why this wasn't put into a file of its own (with other things that are used frequently) and merely
source
d in every script.Admin
Nah. I'm just old.
Admin
Much more fun to have boiler plate templates as the start of all scripts. This way, when the template changes, ALL scripts must be rewritten over the new template. Also, in places that don't do revision control, you can sorta-kinda-maybe tell when a script was written based on the particular boiler plate at the top.
The script in the article, for example, was written some time between 1970 and yesterday.
Admin
There are so many gotchas with aliases, the only reason to use them is when you need to quickly rebind a command to mess with someone.
Admin
Even older that that, m'lud. This, in fact, goes back to the Roman Empire. Which, as we know, did not have zero to indicate successful termination of their C programs (which in turn was one of the main reasons of its downfall).
Admin
if you're not running Bash on a microcontroller ... you should be!
Admin
http://trillian.mit.edu/~jc/humor/ATT_Copyright_true.html
Admin
i think it'd be safer to use, that's what i'd use: echo "try this" > /dev/null; echo $?
as remembering "true = 0 or 1" , and in what cases, is too much energy consuming for me... Universe is just concerning about energy these days..
Admin
By default, Bash exits with status '0', indicating success. Thus the simplest implementation of 'true' is a do-nothing bash script, with just the hashbang line.
TRWTF is copious amount of copyright notices and change logs (version: 1.6) in some such implementations, for example:
Admin
true() { :; } false() { ! :; } file_not_found() { grep <&2-; }
Admin
This is nothing compared to the start of literally ever autoconf-generated ./configure script
Admin
Nobody remarked on the hardcoded ESC sequences? Wtf is wrong with people. ;)
tput is your friend, that way it doesn't really matter (in most cases) what weird terminal emulation people are using.
Admin
if true doesn't work, what makes you think that tput will?
Admin
I once used a Unix distribution where true(1) had originally been implemented as a completely empty file. Then a reseller had added their own copyright to it, without "#" comment markers. This meant that true(1) always failed.
Admin
Reminds me of a story I stumbled across once about the company Unix folks having monthly programming competitions in Bash to see who could write the most useful thing. One of the C programmers was always interested in reviewing the results, but didn't participate other than that for a couple of years.
Then one month he made a submission: A functional C compiler written in Bash. He won that month and nobody was able to top it so the competition kind of faded out after that.