/bin/sh script not behaving as expected

Cary cary at SDF.ORG
Fri Aug 15 03:05:56 UTC 2014


On Fri, Aug 15, 2014 at 01:55:59AM +0000, Cary wrote:
> > On Thu, 14 Aug 2014, Rick Miller wrote:
> > 
> > >Hi all,
> > >
> > >#! /bin/sh
> > >
> > >disks="da2 da1 da0";
> > >
> > >for d in ${disks}; do
> > >  if [ -z "${disk}" -o "${disk}" '>' "${d}" ]; then
> > >     : ${disk:=${d}};
> > >  fi
> > >done
> > 
> > The algorithm is not clear to me,
> 
> Nor me. 
> Rick,  I don't understand the test.  Would just
> 					
> if [ -z "${disk}" ]; then 
> 
> suffice ?  Single-quoting the > operator looks like an error that would have
> prevented the shell from executing the script.

Ok, it is possible. 
You can see that with or without quotes around the comparison operator
the test is the same.

$ if [ foo != bas ] ; then echo bar;fi
bar
$ if [ foo '!=' bas ] ; then echo bar;fi
bar

> > or, more correctly,
> > 
> >   disk=`sysctl -n kern.disks | tr " " "\n" | sort | head -n1`
> > _______________________________________________



-- 
cary at sdf.org
SDF Public Access UNIX System - http://sdf.org


More information about the freebsd-questions mailing list