From owner-freebsd-questions@FreeBSD.ORG Thu Aug 14 14:13:55 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 2C4AEFC6 for ; Thu, 14 Aug 2014 14:13:55 +0000 (UTC) Received: from mail-ig0-x22e.google.com (mail-ig0-x22e.google.com [IPv6:2607:f8b0:4001:c05::22e]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id F0CA52B5E for ; Thu, 14 Aug 2014 14:13:54 +0000 (UTC) Received: by mail-ig0-f174.google.com with SMTP id c1so13668252igq.7 for ; Thu, 14 Aug 2014 07:13:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:date:message-id:subject:from:to:content-type; bh=oYyhvfLbqesAosVuBHKmxssxTF6oEtpRXd2nHWIFidg=; b=SIm6h/eBHZOIAi9yOXnYyZhY1oyhHGy4uXQWTOHDJRoPhw5cNsDns+ZWViSTizFr/V 4Yt4HY0TeaaD3W2sa4kdM18meCQfNrXBwsQuZPrO2XFbWdOWCuPggmaVDXnJy7KAuDJC HZpYaRZ5PYQaGHx5cfYxxWZBCfWsE1tuy8EzTF6PyngfVZ6oi8u/4gUSdbBt9/oWOFY9 VhIBMJpwbgsPc6cIpOjNHa4I7g9nOuTYVPDEjQqPAY87VyFU6LRaBe22D//Yg394K6FW /1o5wAgMi2XJpx40lcJuG9/g8j4cSwdzRc+v+yD1M266xDdsYFGLxFP31RgHlwqt34gA HRUg== MIME-Version: 1.0 X-Received: by 10.42.212.146 with SMTP id gs18mr3237502icb.96.1408025634381; Thu, 14 Aug 2014 07:13:54 -0700 (PDT) Sender: vrwmiller@gmail.com Received: by 10.64.165.73 with HTTP; Thu, 14 Aug 2014 07:13:54 -0700 (PDT) Date: Thu, 14 Aug 2014 10:13:54 -0400 X-Google-Sender-Auth: YzsxzcG21TjRjmujJCL1NRwwC48 Message-ID: Subject: /bin/sh script not behaving as expected From: Rick Miller To: FreeBSD Questions Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.18-1 X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Aug 2014 14:13:55 -0000 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