bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Spaces in args, escapes, and command substitution


From: Eric Blake
Subject: Re: Spaces in args, escapes, and command substitution
Date: Sat, 28 Oct 2006 22:04:29 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Thunderbird/1.5.0.7 Mnenhy/0.7.4.666

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

According to bash@zacglen.com on 10/28/2006 9:42 PM:
>     f1="/a/b/a-000"
>     f2="/a/b/c d-000"
>     touch "a-000.ext"
>     touch "c d-000.ext"
> 
>     for file in "$(basename \"$f1\")"*.ext "$(basename \"$f2\")"*.ext
>     do
>       echo "one=$file"
>     done
> 
>     for file in "`basename \"$f1\"`"*.ext "`basename \"$f2\"`"*.ext
>     do
>       echo "two=$file"
>     done
> -----------
> 
> The backticks work perfectly.
> But the $() gets it very wrong and leaves a double-quote in the result.

That's because `` and $() have different syntax, as required by POSIX.
You should just do $(basename "$f1"), rather than $(basename \"$f1\").

- --
Life is short - so eat dessert first!

Eric Blake             ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFRChM84KuGfSFAYARAgo0AKC1UI0OZPXEqpm3sOk255oaSqr5VACggpaY
vyvKHOXSYcNX5BZQFjdXOVI=
=7InC
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]