From owner-freebsd-questions@FreeBSD.ORG Fri Aug 15 03:05:56 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 B0CD0DF6 for ; Fri, 15 Aug 2014 03:05:56 +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 73719273F for ; Fri, 15 Aug 2014 03:05:55 +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 s7F35ftv027464 (using TLSv1/SSLv3 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits) verified NO); Fri, 15 Aug 2014 03:05:42 GMT Received: (from cary@localhost) by sdf.org (8.14.8/8.12.8/Submit) id s7F35fk4000760; Fri, 15 Aug 2014 03:05:41 GMT Date: Fri, 15 Aug 2014 03:05:41 +0000 From: Cary To: Warren Block , Rick Miller , FreeBSD Questions Subject: Re: /bin/sh script not behaving as expected Message-ID: <20140815030541.GA20578@SDF.ORG> Mail-Followup-To: Warren Block , Rick Miller , FreeBSD Questions References: <20140815015559.GA21249@SDF.ORG> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20140815015559.GA21249@SDF.ORG> User-Agent: Mutt/1.5.23 (2014-03-12) 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 03:05:56 -0000 On Fri, Aug 15, 2014 at 01:55:59AM +0000, Cary wrote: > > On Thu, 14 Aug 2014, Rick Miller wrote: > > > > >Hi all, > > > > > >#! /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. Ok, it is possible. You can see that with or without quotes around the comparison operator the test is the same. $ if [ foo != bas ] ; then echo bar;fi bar $ if [ foo '!=' bas ] ; then echo bar;fi bar > > or, more correctly, > > > > disk=`sysctl -n kern.disks | tr " " "\n" | sort | head -n1` > > _______________________________________________ -- cary@sdf.org SDF Public Access UNIX System - http://sdf.org