From owner-freebsd-questions@FreeBSD.ORG Thu Aug 14 14:36:51 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 DA0179BF for ; Thu, 14 Aug 2014 14:36:51 +0000 (UTC) Received: from mail-ig0-x22d.google.com (mail-ig0-x22d.google.com [IPv6:2607:f8b0:4001:c05::22d]) (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 A79E72E36 for ; Thu, 14 Aug 2014 14:36:51 +0000 (UTC) Received: by mail-ig0-f173.google.com with SMTP id h18so13734013igc.6 for ; Thu, 14 Aug 2014 07:36:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=tzzscxT6zRaoEzv0VKrPMVwPMUdCxgWRVU9EdhRmiM4=; b=p31yROlJsl2KKaIs0bRbJgK/rGQyP1owBgk6abo7bgC5i8aObK31r2TN2kP3CgEuUD eiRNRmC/Y6kUM/jfZNCFJIWuYt7XGxqs0GcDom/4PcPd3Fo6c8rTy8DfRjelco4AuIEE q0s7VOPo7QIUXLgU7OzLbpiWofQI4gQJpbVaCe/ch7i2CDGOWcoWx+qpDHThPjDT9W08 cahPHEddBcnKvt3UJqdCZbPQAV+izaBajM4igiKpUSD38+eFa1cnySGCHLMJRInNZE66 hveWzWe2OiKabf2E/vS/J5Zzn6+kSIS3LbbDFtnRYFAtUJcRS53sY9bEGIlEkeWcbCnf u9BQ== MIME-Version: 1.0 X-Received: by 10.50.122.99 with SMTP id lr3mr58398030igb.10.1408027011084; Thu, 14 Aug 2014 07:36:51 -0700 (PDT) Sender: vrwmiller@gmail.com Received: by 10.64.165.73 with HTTP; Thu, 14 Aug 2014 07:36:51 -0700 (PDT) In-Reply-To: <53ECC716.2020106@qeng-ho.org> References: <53ECC716.2020106@qeng-ho.org> Date: Thu, 14 Aug 2014 10:36:51 -0400 X-Google-Sender-Auth: zavW5McOBgFhsOnYZY47ljIAB-M Message-ID: Subject: Re: /bin/sh script not behaving as expected From: Rick Miller To: Arthur Chance Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.18-1 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: Thu, 14 Aug 2014 14:36:51 -0000 On Thu, Aug 14, 2014 at 10:26 AM, Arthur Chance wrote= : > On 14/08/2014 15:13, 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=E2=80=99m hoping that fresh pairs of eyes might help me i= dentify >> 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; >> >> >> [ snip ] >> >> > Your problem is in > > : ${disk:=3D${d}}; > > From man sh > > ${parameter:=3Dword} > Assign Default Values. If parameter is unset or null, the expan= =E2=80=90 > sion of word is assigned to parameter. In all cases, the final > value of parameter is substituted. Quoting inside word does not > prevent field splitting or pathname expansion. Only variables, > not positional parameters or special parameters, can be assigned > in this way. > > Once $disk has been set this form won't reset it. > > You should have > > disk=3D"$d" > Excellent, thanks! My understanding of parameter expansion was flawed. I appreciate the info. --=20 Take care Rick Miller