Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Aug 2014 01:55:59 +0000
From:      Cary <cary@SDF.ORG>
To:        Warren Block <wblock@wonkity.com>
Cc:        Rick Miller <vmiller@hostileadmin.com>, FreeBSD Questions <freebsd-questions@freebsd.org>
Subject:   Re: /bin/sh script not behaving as expected
Message-ID:  <20140815015559.GA21249@SDF.ORG>
In-Reply-To: <alpine.BSF.2.11.1408141143010.53473@wonkity.com>
References:  <CAHzLAVE1E8hZvZEnDko8-7cfx6JYypezi3oxs4vKKjxDzSzZnw@mail.gmail.com> <alpine.BSF.2.11.1408141143010.53473@wonkity.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"

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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20140815015559.GA21249>