[Top][All Lists]

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

Re: Spaces in args, escapes, and command substitution

From: bash
Subject: Re: Spaces in args, escapes, and command substitution
Date: Sun, 29 Oct 2006 15:19:29 +1100

>According to address@hidden 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\").

That's crazy!

You have nested double quotes which don't need escaping?!

Let me think aloud:

    The first thing one encounters left-to-right is a double-quote.
    So, logic says that the quoted string is terminated by matching

    Ok, so that means that the above is:
        "$(basename "
    followed by:
    followed by:

    which means that any spaces in $f1 are apparently unquoted and will
    therefore be subject to arg splitting.

    Therefore, there must be appropriate kludges in bash which make it work,
    despite the way in which it defies commonsense.

Looks like POSIX and commonsense are two different things.


reply via email to

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