From owner-freebsd-questions@FreeBSD.ORG Fri Aug 15 07:32:40 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 4B509BB3 for ; Fri, 15 Aug 2014 07:32:40 +0000 (UTC) Received: from blue.qeng-ho.org (blue.qeng-ho.org [217.155.128.241]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D5DCD2407 for ; Fri, 15 Aug 2014 07:32:39 +0000 (UTC) Received: from fileserver.home.qeng-ho.org (localhost [127.0.0.1]) by fileserver.home.qeng-ho.org (8.14.7/8.14.5) with ESMTP id s7F7Was1006926; Fri, 15 Aug 2014 08:32:36 +0100 (BST) (envelope-from freebsd@qeng-ho.org) Message-ID: <53EDB794.3040702@qeng-ho.org> Date: Fri, 15 Aug 2014 08:32:36 +0100 From: Arthur Chance User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-Version: 1.0 To: Warren Block , Rick Miller Subject: Re: /bin/sh script not behaving as expected References: In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Cc: FreeBSD Questions 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: Fri, 15 Aug 2014 07:32:40 -0000 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.