Is there a way to tell bash/zsh to not parse the quotes at all but give them to a shell function verbatim?
$ argtest abc def "ghi jkl" $'mno\tpqr' $'stu\nvwx'
abc
def
"ghi jkl"
$'mno\tpqr'
$'stu\nvwx'
You might be thinking why I don't just do
argtest abc def '"ghi jkl"' "$'mno\tpqr'" "$'stu\nvwx'"
But the argtest
function I'm trying to create tries to wrap around other commands which can have noglob
prefixes. So I need a way of being able to tell apart *
and '*'
.
In zsh
, you can use the q
parameter expansion flag, but it's messy. One q
escapes individual characters as necessary; two expands the text in single quotes; three in double quotes. (The notation ${:-stuff}
simply expands to the text following :-
; it's a wrapper that allows you to create anonymous parameters.)
$ echo "foo bar"
foo bar
$ echo ${(qq):-"foo bar"}
'foo bar'
$ echo ${(qqq):-"foo bar"}
"foo bar"
$ argtest () {
function> echo "$1"
function> }
$ argtest "foo bar"
foo bar
$ argtest ${(qqq):-"foo bar"}
"foo bar"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With