/bin/sh script not behaving as expected

Cary cary at SDF.ORG
Fri Aug 15 01:56:20 UTC 2014


On Thu, Aug 14, 2014 at 11:51:53AM -0600, Warren Block wrote:
> On Thu, 14 Aug 2014, Rick Miller wrote:
> 
> >Hi all,
> >
> >I have shell code whose purpose is to determine the first disk in the
> >system where FreeBSD is to be installed.  The code is not behaving as
> >expected and I?m hoping that fresh pairs of eyes might help me identify the
> >problem.
> >
> >Here is the script along with an explanation of the implementation and
> >description of the problem:
> >
> >#! /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.

> but I would do something simpler like
> 
>   disk=`cd /dev; ls da? | head -n1`
> 
> or, more correctly,
> 
>   disk=`sysctl -n kern.disks | tr " " "\n" | sort | head -n1`
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at freebsd.org"

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


More information about the freebsd-questions mailing list