Date: Thu, 14 Aug 2014 10:36:51 -0400 From: Rick Miller <vmiller@hostileadmin.com> To: Arthur Chance <freebsd@qeng-ho.org> Cc: FreeBSD Questions <freebsd-questions@freebsd.org> Subject: Re: /bin/sh script not behaving as expected Message-ID: <CAHzLAVHH1t0WN8=BOzVsm=e0SMoqi9CCE75=EaOFSLz=ns_wpA@mail.gmail.com> In-Reply-To: <53ECC716.2020106@qeng-ho.org> References: <CAHzLAVE1E8hZvZEnDko8-7cfx6JYypezi3oxs4vKKjxDzSzZnw@mail.gmail.com> <53ECC716.2020106@qeng-ho.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Aug 14, 2014 at 10:26 AM, Arthur Chance <freebsd@qeng-ho.org> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAHzLAVHH1t0WN8=BOzVsm=e0SMoqi9CCE75=EaOFSLz=ns_wpA>