/bin/sh script not behaving as expected

Warren Block wblock at wonkity.com
Thu Aug 14 17:51:55 UTC 2014


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`


More information about the freebsd-questions mailing list