I have tried the following:
myprogram $'Hello $HOME'
But it did not work (the command line argument received by myprogram
was Hello $HOME
, and not the value of $HOME
).
Apart from interpreting the C-style backslash-escapes, $'...'
works like a single-quoted string. At least Bash's manual mentions this, right at the end of the page on "ANSI-C quoting":
The expanded result is single-quoted, as if the dollar sign had not been present.
So, no. That's probably why they chose to use single-quotes for that (or the other way around), though I don't know about the history of the feature.
You'll have to use double-quotes, and change the quotes as necessary. i.e.
$ myprogram "Hello $HOME"
or with a tab mixed in
$ myprogram $'Hello\t'"$HOME"
$""
so double-quotes got used for that? But it doesn't matter enough that I would start looking.
You have to write it as
$ myprogram "Hello $HOME"
Bash will preserve the literal meaning of anything enclosed within double quotes except $,`(back-tick) or .So Here it considers "Hello" as the value while $Hello preserves its value as a variable.
myprogram "Hello $HOME"
?