Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: there should be a way to echo with quotes or escaping



On Mar 23,  2:00pm, Dave Yost wrote:
} 
} If there is such a feature, I didn't see it mentioned under the echo 
} command in the man page.

The way to do this is with parameter expansion:

Z% raw="abc def"
Z% echo ${(q)raw}
abc\ def
Z% echo ${(qq)raw}
'abc def'
Z% echo ${(qqq)raw}
"abc def"
Z% echo ${(qqqq)raw}
$'abc def'

(More than four "q"s doesn't change anything after that.)

To skip the assignment to "raw", just:

Z% echo ${(q):-"abc def"}
abc\ def

Of course you're really better off using "print -R" than "echo", because
"echo" may re-interpret backslashes etc. embedded in its arguments.



Messages sorted by: Reverse Date, Date, Thread, Author