Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Aug 2014 08:32:36 +0100
From:      Arthur Chance <freebsd@qeng-ho.org>
To:        Warren Block <wblock@wonkity.com>, Rick Miller <vmiller@hostileadmin.com>
Cc:        FreeBSD Questions <freebsd-questions@freebsd.org>
Subject:   Re: /bin/sh script not behaving as expected
Message-ID:  <53EDB794.3040702@qeng-ho.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 14/08/2014 18:51, 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, 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`

Not sure that will work on all machines. "sysctl kern.disks" on my 
machine shows cd0 as well as other disks, and that will sort ahead of 
da? disks.

Anyway, whatever this is for, why not simply tell the shell script which 
disk to use? It's not like it's going to change very often, and it's 
going to be da0 or ada0 in 99% of cases.



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