/bin/sh script not behaving as expected
Arthur Chance
freebsd at qeng-ho.org
Fri Aug 15 07:32:40 UTC 2014
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.
More information about the freebsd-questions
mailing list