Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
protect backslash before space
- X-seq: zsh-users 30470
- From: Ray Andrews <rayandrews@xxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: protect backslash before space
- Date: Wed, 1 Apr 2026 09:08:32 -0700
- Archived-at: <https://zsh.org/users/30470>
- List-id: <zsh-users.zsh.org>
#!/usr/bin/zsh
alias test='noglob _test'
function _test ()
{
# .... lines of code
eval echo $@
# ... lines of code
}
ls -- $@
run, testing on file 'junk junk':
5 /aWorking/Zsh/Source/Wk 3 % . test junk* && test junk*
'junk junk'
junk junk
5 /aWorking/Zsh/Source/Wk 3 % . test junk\ * && test
'junk\ *'
'junk junk'
junk junk
--------------------------
I like my functions to be able to see their own tail. This is one
of the first brick walls I threw myself against when I first
started using zsh and I understand that it's asking the shell not
to do what it's designed to do. Anyway, it turned out that
'noglob' came close, and then 'eval' to make the glob expansion
when the time came. Works well, except for the backslash before a
space. 'noglob' does not protect it. I can work around it by
simply quoting as I've done in the second run above. But is there
a better way? Reason I bring it up is that I was wondering if
that recent cool stuff that Eric Wybouw was doing that boiled down
to:
BUFFER="= ${(q-)${${BUFFER#=}# }}"
... might point to a solution: some way of 'auto quoting' so that
I'd not have to manually add the quotes as above. Or some other way
of preserving the backslash.
BTW, question: why does the script version above add the single
quotes to indicate a single filename whereas the 'eval'ed version
doesn't see the need? I'd vaguely expect the single quotes in
both.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author