[aklug] Re: bash assert function?

From: Kenneth D. Weinert <kenw@quarter-flash.com>
Date: Fri May 25 2012 - 03:21:25 AKDT

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 05/23/2012 11:30 PM, Christopher Howard wrote:
> On 05/23/2012 07:09 PM, bryanm@acsalaska.net wrote:
>
>> Like many bash problems, this is a quoting issue. When you pass
>> "a b" to the function, the quotes are removed, leaving a b
>
>> You can see this with echo: $ echo "a b" = "a b" a b = a b
>
>> And then, when you do the test: $ [ a b = a b ] -bash: [: too
>> many arguments
>
>> You need to pass the arguments to the function in a way that will
>> leave any included spaces quoted (or escaped). In this
>> particular example, you could do this: $ echo '"a b"' = '"a b"'
>> "a b" = "a b"

One alternative to messing around with quoting is to change the IFS
value. It might not fit into this particular situation, but it's a
technique that can be very useful under the right circumstances.

>
>> In fact, I think the single quotes may work as a fairly general
>> solution, but don't ... (ahem) ... quote me on that. Depending
>> on what you're actually passing to the function, you may have to
>> play around with the quoting syntax a bit.
>
>> -- Bryan Medsker bryanm@acsalaska.net
>
>
>
> Thanks. After looking into this some more, I think the answer is
> that... there isn't one. The aforementioned quoting issues prevent
> one from creating an assert function that can take /any/ kind of
> expression (including, especially, string comparisons with
> variables that contain multiple words).
>
> At the end of the day, it is simple enough just to stick the test
> directly into the script and append a exit call and message. So
> that's the approach I'm taking.
>
> --------- To unsubscribe, send email to <aklug-request@aklug.org>
> with 'unsubscribe' in the message body.
>

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJPv2snAAoJELwlFgJPb4vsJW4IAKJxM0YIzASAMCPKB7gAwY0m
PINE8fqwfKMj06vna5lmAth4ofiT/PkgUO+Sl0tJnpjfhoaiHL6F3CxWyxNL73yr
+Bhun7S32AWDAf8L4bGjohixzUEzvDQ5Da25DIU5sGG/XJ5a6oveK79IOxsSFPln
iSUsLBT0LsWgPBN/FAeyjCXAjUdyXyjiJhrbJDWGiZJ+Y2By+VIBAkkVoeLCdR18
TofYJfmsUW/lPSsxIUqa+vHw6OybmVZbFL/kqHC+7HjXhekqiumcqQjcFFXMo8Rh
+E9pAKCO2FsP4C3RycsVuXpSjM8bGT0tAJ1djwjlo126jG7+9h7mjmPZKIvLHXs=
=foQh
-----END PGP SIGNATURE-----
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Fri May 25 03:21:28 2012

This archive was generated by hypermail 2.1.8 : Fri May 25 2012 - 03:21:29 AKDT