[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bash messes up spaces in command line agruments.
From: |
Eric Blake |
Subject: |
Re: Bash messes up spaces in command line agruments. |
Date: |
Tue, 06 May 2008 18:57:28 -0600 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080421 Thunderbird/2.0.0.14 Mnenhy/0.7.5.666 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Herrmann, Justin on 5/6/2008 8:20 AM:
| Description: When I try to pass strings inside double or single quotes
| as command line arguments to my Bash script, leading spaces, trailing
| spaces, and multiple grouped embedded spaces are removed from the
| string.
Of course they are, but that's because the bug is in your script. You
didn't quote properly.
| #!/bin/bash
| echo $#
| for ((index = 0; index <= $#; index++))
| do
| echo "$index |$(eval echo \${$index})|"
Based on your command, you really want something like:
~ echo "$index |$(eval echo \"\${$index}\")|"
Or more efficiently:
~ eval 'echo "$index |$'"$index"'|"'
- --
Don't work too hard, make some time for fun as well!
Eric Blake ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkgg/ncACgkQ84KuGfSFAYBGTQCfRysjoyKq5zmTLnHEf9qizG/R
ZgAAoLFrDQQzr56rZ1DrMBqf8sdsiy0f
=0F/T
-----END PGP SIGNATURE-----