* Quoting problems
@ 2016-02-16 7:53 Sebastian Gniazdowski
2016-02-16 9:33 ` Peter Stephenson
0 siblings, 1 reply; 3+ messages in thread
From: Sebastian Gniazdowski @ 2016-02-16 7:53 UTC (permalink / raw)
To: Zsh hackers list
[-- Attachment #1: Type: text/plain, Size: 1042 bytes --]
Hello,
# source test_script > a
# source ./a
./a:156: unmatched "
./a:157: invalid function definition
It's about following line:
[[ $#exp -eq 1 && "${exp[1]//\}" = "${word//\}"(|\(N\)) ]]
The first and second backslash aren't quoted and cause the two '{' to
be unbound. Other quoting styles (q, qqq, qqqq) also fail in general
(with e.g. parse errors, also with an 'unmatched "'). I think that
quoting means: content can be anything, special characters will be
taken care of – so this is a problem.
The test script is:
# To be sourced
for k in _expand; do
echo "if [[ \"\${functions[$k]}\" != ${(qq)functions[$k]} ]]; then
functions[$k]=${(qq)functions[$k]}
fi"
done
I also attach short version of the result:
if [[ "${functions[_expand]}" != ' setopt localoptions nonomatch' ]]; then
functions[_expand]='[[ $#exp -eq 1 && "${exp[1]//\}" =
"${word//\}"(|\(N\)) ]]'
fi
- sourcing this will fail because of the unquoted backslash.
Best regards,
Sebastian Gniazdowski
[-- Attachment #2: test_script --]
[-- Type: application/octet-stream, Size: 164 bytes --]
# To be sourced
for k in _expand; do
echo "if [[ \"\${functions[$k]}\" != ${(qq)functions[$k]} ]]; then
functions[$k]=${(qq)functions[$k]}
fi"
done
[-- Attachment #3: snap-2016.02.16_07:52:44 --]
[-- Type: application/octet-stream, Size: 170 bytes --]
if [[ "${functions[_expand]}" != ' setopt localoptions nonomatch' ]]; then
functions[_expand]='[[ $#exp -eq 1 && "${exp[1]//\}" = "${word//\}"(|\(N\)) ]]'
fi
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Quoting problems
2016-02-16 7:53 Quoting problems Sebastian Gniazdowski
@ 2016-02-16 9:33 ` Peter Stephenson
2016-02-16 10:11 ` Sebastian Gniazdowski
0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2016-02-16 9:33 UTC (permalink / raw)
To: Zsh hackers list
On Tue, 16 Feb 2016 08:53:05 +0100
Sebastian Gniazdowski <sgniazdowski@gmail.com> wrote:
> Hello,
> # source test_script > a
> # source ./a
> ./a:156: unmatched "
> ./a:157: invalid function definition
>
>
> It's about following line:
> [[ $#exp -eq 1 && "${exp[1]//\}" = "${word//\}"(|\(N\)) ]]
>
> The first and second backslash aren't quoted and cause the two '{' to
> be unbound.
Looking at your code, I think you'll find this is because you're using
echo without the option not to expand bacslashes. Try "echo -E" or
"print -r". (I'd recommend "print" if this is zsh-specific as echo
is mostly there for backward compatibility, although there's no reason
it shouldn't work here.)
pws
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Quoting problems
2016-02-16 9:33 ` Peter Stephenson
@ 2016-02-16 10:11 ` Sebastian Gniazdowski
0 siblings, 0 replies; 3+ messages in thread
From: Sebastian Gniazdowski @ 2016-02-16 10:11 UTC (permalink / raw)
To: Peter Stephenson; +Cc: Zsh hackers list
On 16 February 2016 at 10:33, Peter Stephenson <p.stephenson@samsung.com> wrote:
> Looking at your code, I think you'll find this is because you're using
> echo without the option not to expand bacslashes. Try "echo -E" or
> "print -r". (I'd recommend "print" if this is zsh-specific as echo
> is mostly there for backward compatibility, although there's no reason
> it shouldn't work here.)
Thanks this helps. As for the echo, I go towards habit of using it
only for debug messages, still forget this sometimes
Best regards,
Sebastian Gniazdowski
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-02-16 10:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-16 7:53 Quoting problems Sebastian Gniazdowski
2016-02-16 9:33 ` Peter Stephenson
2016-02-16 10:11 ` Sebastian Gniazdowski
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).