View Single Post
  #4   (View Single Post)  
Old 1st January 2016
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,128
Default

Yes, I know that the Korn shell [[ .... ]] constructs allows it. On OpenBSD it also does and you don't need to quote it.
Code:
$ if [[ 'zzz' > 'aaa' ]]; then echo Greater ; fi   
Greater
$ ls -l aaa
ls: aaa: No such file or directory
$ if [[ 'zzz' \> 'aaa' ]]; then echo Greater ; fi
ksh: syntax error: `"zzz"' missing expression operator
$
But that is not portable for /bin/sh of for example FreeBSD:
Code:
$ echo $SHELL
/bin/sh
$ uname
FreeBSD
$ if [[ 'zzz' > 'aaa' ]]; then echo Greater ; fi 
[[: not found
$ ls -l aaa
-rw-r--r--  1 j65nko  j65nko  0 Jan  1 16:39 aaa
$ if [ 'zzz' > 'aaa' ]; then echo Greater ; fi
Greater
$ ls -l aaa
-rw-r--r--  1 j65nko  j65nko  0 Jan  1 16:42 aaa
$ rm aaa
$ if [ 'zzz' \> 'aaa' ]; then echo Greater ; fi
Greater
$ ls -l aaa
ls: aaa: No such file or directory
$
But as you see, there the single [ ...... ] works. As stated in the FreeBSD sh(1) man page under the heading Built-in Commands:

Code:
[	     A built-in	equivalent of test(1).
OpenBSD's ksh which can be run as sh lacks the '<' and '>' string comparison of OpenBSD's /bin/[. This difference is documented in the manual pages of that shell, but I just did not realize that
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote