2

From bash manual

Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard

A double-quoted string preceded by a dollar sign (‘$’) will cause the string to be translated according to the current locale. If the current locale is C or POSIX, the dollar sign is ignored. If the string is translated and replaced, the replacement is double-quoted.

I wonder when the kinds of expansions happen?

I guess they must happen after parsing. If that is correct, when do they happen with respect to shell expansions such as brace expansion, parameter expansion, and filename expansion?

Thanks.

1 Answer 1

3

$'...' works just like any other quoting, except it just gives alternate ways of presenting some characters.

These both print {foo,bar}:

echo $'\x7b'foo,bar}
echo "{"foo,bar}

...while this triggers brace expansion and prints foo bar:

echo {foo,bar}

Given foo=abc, these print $foo:

echo $'\x24'foo
echo "$"foo

...while this expands the variable, and prints abc:

echo $foo

If there's a file called abc.txt, these print abc.txt:

echo "a"*.txt
echo $'\x61'*.txt

I can only assume the same is true for $"..".

1
  • 1
    great examples :)
    – zdim
    Commented Jul 25, 2019 at 17:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .