From owner-freebsd-questions@FreeBSD.ORG Thu Aug 14 14:49:22 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 091D5C97 for ; Thu, 14 Aug 2014 14:49:22 +0000 (UTC) Received: from smtpy.mta.ca (smtpy.mta.ca [138.73.1.125]) (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 D1A27202E for ; Thu, 14 Aug 2014 14:49:21 +0000 (UTC) Received: from qemg.mta.ca ([138.73.29.51]:49186 helo=qemg.org) by smtpy.mta.ca with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.82) (envelope-from ) id 1XHwG9-0002KM-Ba; Thu, 14 Aug 2014 11:44:09 -0300 Date: Thu, 14 Aug 2014 11:49:12 -0300 (ADT) From: Andrew Hamilton-Wright To: Rick Miller Subject: Re: /bin/sh script not behaving as expected In-Reply-To: Message-ID: References: User-Agent: Alpine 2.11 (BSF 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed 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:49:22 -0000 On Thu, 14 Aug 2014, Rick Miller wrote: [ ... condensed ... ] > for d in ${disks}; do > if [ -z "${disk}" -o "${disk}" '>' "${d}" ]; then > : ${disk:=${d}}; > fi > done [ ... condensed ... ] > # $disk; If $disk is unset/null, $disk is set to $d. If $disk is set, it ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ I believe that this is your problem -- you want to update the value of disk whenever your if statement is true, whereas the above will do so only when the if statement is true _and_ your variable is unset. Is there a reason you are not simply using: disk=${d} as the assignment in your if statement? Andrew.