Date: Thu, 14 Aug 2014 10:13:54 -0400 From: Rick Miller <vmiller@hostileadmin.com> To: FreeBSD Questions <freebsd-questions@freebsd.org> Subject: /bin/sh script not behaving as expected Message-ID: <CAHzLAVE1E8hZvZEnDko8-7cfx6JYypezi3oxs4vKKjxDzSzZnw@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
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=E2=80=99m hoping that fresh pairs of eyes might help me iden= tify the problem. Here is the script along with an explanation of the implementation and description of the problem: #! /bin/sh disks=3D"da2 da1 da0"; for d in ${disks}; do if [ -z "${disk}" -o "${disk}" '>' "${d}" ]; then : ${disk:=3D${d}}; fi done echo $disk; # Given the input(s), $disks, the expected behavior of the above code is to # set $disk to "da0" which ends up being the chosen disk to install FreeBSD= . # # The for() loop iterates over $disks. The if() statement tests the status of # $disk; If $disk is unset/null, $disk is set to $d. If $disk is set, it # compares the binary value of $disk to $d and should select the element with # the lower binary value. In this particular case, it is expected to selec= t # da0 as the ultimate value for $disk, but in practice, it appears to set # $disk to da2 instead. # # NOTE: This is on FreeBSD 10. The code has been tested in bash as well, which # returns the same results. TIA --=20 Take care Rick Miller
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAHzLAVE1E8hZvZEnDko8-7cfx6JYypezi3oxs4vKKjxDzSzZnw>