[aklug] Re: bash assert function?

From: Christopher Howard <christopher.howard@frigidcode.com>
Date: Wed May 23 2012 - 21:30:15 AKDT

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

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"
>
> 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.

- --
frigidcode.com
indicium.us
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJPvcdnAAoJEI2DxlFxTtgdcPoH/28XxYVyUlqAc3Kz/C1EPeAP
N75npn2STbu7sIDynqZhexZWA2WiXB2evIboX9IsttieTmRshyGbQU45+emaWXH7
YZputbIBgjQbsc9ACJmndSqeYtl3dnoKeFdGEhEKkwBxj32paHqY8lQcG6xQlwcg
Ceur9vZD+33ik192PpVY6LFkQEa3YIquKDyxKXsPckRX2H2kaBjkUwHu6RfgUuiI
V2H+8bfG0p3jgNuKujU5vsXEpkjATbTTZoriya0zIxOGUgXUOUaWsVx8b5T2+GTN
jIb+4akBySSccndng5kHXabL8xhZR/BZ3U13WMUgpabArPgZeh9Ng/IrILygL9g=
=PBlh
-----END PGP SIGNATURE-----
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Wed May 23 21:26:05 2012

This archive was generated by hypermail 2.1.8 : Wed May 23 2012 - 21:26:05 AKDT