From owner-freebsd-questions@FreeBSD.ORG Fri Aug 15 01:56:19 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 EC9708FE for ; Fri, 15 Aug 2014 01:56:19 +0000 (UTC) Received: from sdf.lonestar.org (mx.sdf.org [192.94.73.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mx.sdf.org", Issuer "SDF.ORG" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id AF52E2E8A for ; Fri, 15 Aug 2014 01:56:18 +0000 (UTC) Received: from sdf.org (IDENT:cary@sdf.lonestar.org [192.94.73.15]) by sdf.lonestar.org (8.14.8/8.14.5) with ESMTP id s7F1txjR001785 (using TLSv1/SSLv3 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits) verified NO); Fri, 15 Aug 2014 01:55:59 GMT Received: (from cary@localhost) by sdf.org (8.14.8/8.12.8/Submit) id s7F1txvP002965; Fri, 15 Aug 2014 01:55:59 GMT Date: Fri, 15 Aug 2014 01:55:59 +0000 From: Cary To: Warren Block Subject: Re: /bin/sh script not behaving as expected Message-ID: <20140815015559.GA21249@SDF.ORG> Mail-Followup-To: Warren Block , Rick Miller , FreeBSD Questions References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Cc: Rick Miller , 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 01:56:20 -0000 On Thu, Aug 14, 2014 at 11:51:53AM -0600, 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, Nor me. Rick, I don't understand the test. Would just if [ -z "${disk}" ]; then suffice ? Single-quoting the > operator looks like an error that would have prevented the shell from executing the script. > 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` > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org" -- cary@sdf.org SDF Public Access UNIX System - http://sdf.org