<div dir="ltr">I believe it was significant when /bin/sh was really /bin/sh and not bash in sh mode<div><br></div><div>For example:</div><div><br></div><div>root@hyclak:~ # ls -l /bin/sh<br><br>lrwxrwxrwx. 1 root root 4 Sep 25 17:01 /bin/sh -> bash<br><br>root@hyclak:~ # cat /etc/redhat-release<br><br>CentOS release 6.7 (Final)</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 6, 2015 at 5:21 PM, <span dir="ltr"><<a href="mailto:jep200404@columbus.rr.com" target="_blank">jep200404@columbus.rr.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Which shell test would you choose? Why?<br>
Would you choose a test not shown below? Why?<br>
<br>
I saw a shell test like [ "z${1}" = "z" ],<br>
which got me wondering, why bother with the 'z'?<br>
Is there some subtle behavior, perhaps when there<br>
is no "${1}" argument? So I experimented.<br>
<br>
These tests worked the same:<br>
<br>
[ "${1:+is_set}" != "is_set" ]<br>
[ "z${1}" = "z" ]<br>
[ "${1}" = "" ]<br>
<br>
The last of those above is curious.<br>
Since it works the same as with 'z', why bother with the 'z'?<br>
<br>
Only [ "${#}" -lt 1 ] was different,<br>
and seems more strictly correct<br>
unless an empty first argument is to be treated the<br>
same as no first argument.<br>
<br>
[user@colug ~]$ cat boo.sh<br>
#!/bin/sh<br>
<br>
a="${1:+is_set}"<br>
echo "a is >$a<"<br>
<br>
if [ "${1:+is_set}" != "is_set" ]; then<br>
echo one<br>
fi<br>
<br>
b="z${1}"<br>
echo "b is >$b<"<br>
<br>
if [ "z${1}" = "z" ]; then<br>
echo two<br>
fi<br>
<br>
c="${1}"<br>
echo "c is >$c<"<br>
<br>
if [ "${1}" = "" ]; then<br>
echo tree<br>
fi<br>
<br>
d="${#}"<br>
echo "d is >$d<"<br>
<br>
if [ "${#}" -lt 1 ]; then<br>
echo for<br>
fi<br>
[user@colug ~]$ ./boo.sh<br>
a is ><<br>
one<br>
b is >z<<br>
two<br>
c is ><<br>
tree<br>
d is >0<<br>
for<br>
[user@colug ~]$ ./boo.sh ''<br>
a is ><<br>
one<br>
b is >z<<br>
two<br>
c is ><<br>
tree<br>
d is >1<<br>
[user@colug ~]$ ./boo.sh ' '<br>
a is >is_set<<br>
b is >z <<br>
c is > <<br>
d is >1<<br>
[user@colug ~]$ ./boo.sh '' world<br>
a is ><<br>
one<br>
b is >z<<br>
two<br>
c is ><<br>
tree<br>
d is >2<<br>
[user@colug ~]$ ./boo.sh ' ' world<br>
a is >is_set<<br>
b is >z <<br>
c is > <<br>
d is >2<<br>
[user@colug ~]$ ./boo.sh hello world<br>
a is >is_set<<br>
b is >zhello<<br>
c is >hello<<br>
d is >2<<br>
[user@colug ~]$<br>
_______________________________________________<br>
colug-432 mailing list<br>
<a href="mailto:colug-432@colug.net">colug-432@colug.net</a><br>
<a href="http://lists.colug.net/mailman/listinfo/colug-432" rel="noreferrer" target="_blank">http://lists.colug.net/mailman/listinfo/colug-432</a><br>
</blockquote></div><br></div>