BLU Discuss list archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Discuss] through the looking glass
- Subject: [Discuss] through the looking glass
- From: jdm at moylan.us (dan moylan)
- Date: Sat, 2 Jun 2018 12:42:00 -0400
richard pieri writes: On 6/1/2018 7:32 PM, dan moylan wrote: >> also b2 writes out empty files abc and xyz. >> >> i've surely missed something fundamental, or did i just >> step into an alternate universe? > What you missed isn't so obvious. > "[" is a synonym for /bin/test with the caveat that a closing "]" is > required. What's happening is that "[ $st1 > $st2 ]" becomes: > /bin/test abc > xyz > "/bin/test abc" returns true, and you get an empty file because test > generates no output, only return codes 0 (true) or 1 (false). > The portable fix is to rewrite your logic because the test command only > allows for "=" and "!=" in string comparisons. > The bash-specific fix is to change your single brackets to double > brackets: "[[ $st1 > $st2 ]]". "[[" is a bash built-in and it bypasses > all of the above problems. But it's not portable. thanks for your lucid explanation. looking at o'reilly's "learning the bash shell" 2nd edition, page 118, the < and > comparisons certainly seem to be allowed. nowhere in the book have i been able to find a discussion of using [[ and ]] (though i have some vague recollection of having run into that before). escaping the comparison operators seems to work as well. which might be preferred? not portable? where would that be? thanks again, ole dan j. daniel moylan 84 harvard ave brookline, ma 02446-6202 617-777-0207 (cel) jdm at moylan.us www.moylan.us [no html pls]
- Follow-Ups:
- [Discuss] through the looking glass
- From: slitt at troubleshooters.com (Steve Litt)
- [Discuss] through the looking glass
- From: richard.pieri at gmail.com (Richard Pieri)
- [Discuss] through the looking glass
- Prev by Date: [Discuss] Jekyll users, experts, developers anywhere?
- Next by Date: [Discuss] through the looking glass
- Previous by thread: [Discuss] through the looking glass
- Next by thread: [Discuss] through the looking glass
- Index(es):