Newsgroups: comp.unix.shell Date: Sun, 16 Oct 2005 17:44:52 +0200
> How to quote within the "$()" in posix compatible shells? > > I tried all the following but none of them worked. I need the "$()" > notation because it is actually part of my long expression that have more > "$()" in it. > > fname='a b c' > echo "$(basename $fname)" > echo "$(basename '$fname')" > echo "$(basename \"$fname\")" > echo "$(basename ${fname})"
This is what I do in bash. I don't know the specifics of POSIX compliance.
echo "$(basename "$fname")"
Notice that the dquotes inside the $() do the right thing. I believe bash starts a recursive processing of the innards of $() in unquoted mode, but quotes the captured command output when pasting it into the echo command.
Enrique Perez-Terron