Re: chere problem with directories with single quote marks

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: chere problem with directories with single quote marks

Dave-50
Eric said:

>According to Tom Plunket on 12/23/2005 11:48 PM:
>>
>>        SHELL_CMD="-l -c \\\"cd '%L'; exec $SHELL_EXE\\\""
>>
>> As you can see, this is clearly "wrong" for folders with a
>> single-quote mark in them.
>>
>> My local fix was just to edit the registry and change '%L' to "%L".
>> Obviously this affects the handling of this feature with folders that
>> have a double-quote mark in them, but as I only use single quotes
>> (e.g. "Debbie's Truck" or "Craig's List"), it Works For Me.  ;)
>
> Window's allows ' but not " in filenames.  However, Windows also allows $
> in filenames, so switching to double quotes would trade the problems with
> ' to problems with $.  And you need quoting, or spacing would be
> corrupted.  Off the top of my head, I can only think of one way that might
> preserve ', $, and spaces in the problematic %L when dumped literally into
> a shell script, but I don't know if Windows SHELL_CMD can handle embedded
> newlines.  In a normal shell window,
>
> $ xargs -0 << 'EOF'
> > a  '$b
> > EOF
> a  '$b
>
> the here-doc correctly preserved the input string.  So applying that to
> the above problem, the registry entry MIGHT work (untested by me) if it is
> written as:
>
> SHELL_CMD="-l -c \\\"xargs -0 cd << 'EOF'\n%L\nEOF\nexec $SHELL_EXE\\\""

Hmmm. It appears that I haven't handled this case consistently. I'll have a look
at getting both ' and $ to work properly.

Thanks for the report.

Dave.
chere maintainer

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com 


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

Reply | Threaded
Open this post in threaded view
|

Re: chere problem with directories with single quote marks

Eric Blake (cygwin)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Dave on 1/3/2006 2:03 PM:

>>
>>the here-doc correctly preserved the input string.  So applying that to
>>the above problem, the registry entry MIGHT work (untested by me) if it is
>>written as:
>>
>>SHELL_CMD="-l -c \\\"xargs -0 cd << 'EOF'\n%L\nEOF\nexec $SHELL_EXE\\\""
>
>
> Hmmm. It appears that I haven't handled this case consistently. I'll have a look
> at getting both ' and $ to work properly.

Scratch my above example; cd is a shell builtin, so it won't work from
xargs.  I did

$ mkdir "a'b  \$c"

for my experiments (make sure ', $, and multiple spaces make it through
okay).  In bash and zsh, the following works on the command line:

cd "`cat<<\eof
a'b  $c
eof
`"

(and you could use $() instead of ``).  But ` and ) are also valid
characters in Windows filenames, and bash, zsh, and pdksh all have bugs in
parsing here-docs inside command substitutions.

For example, bash fails on:
cd "$(cat<<\eof
`
eof
)"

Somehow, it thinks that ` starts a nested command substitution, even
though it appears inside of a quoted here-doc.  (And in the case of `, you
must use $() instead of ``, since POSIX states that `` doesn't nest
without proper quoting).

Also, bash has a bug when the command-substitution is not also quoted:
$ echo $(cat<<\eof
> `
> eof
> )

Again, bash (both 3.0 and 3.1) thinks the ` starts a nested command
substitution, and is waiting for a matching ` before executing anything.

Believe it or not, the ONLY shell which I found which correctly parses all
the troublesome characters, as required by POSIX, is ash, which is the
least POSIX-compliant of them all!

Sorry, but I don't know ANY portable construct that works in all 4 cygwin
shells (ash, bash, zsh, and pdksh).

Plus there is still the matter of translating a valid command line into a
registry entry that Windows can parse; I don't know if you can embed
newlines, and without embedded newlines, a here-doc will not work.

All I can do is wish you good luck.

- --
Life is short - so eat dessert first!

Eric Blake             [hidden email]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDu9VB84KuGfSFAYARAui9AKDXZQzCZdkWOEpX0qEGTJhj7pXNkACfZnH9
zeDyPIIzfuu8TMcwtW5hQ0k=
=TRli
-----END PGP SIGNATURE-----


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

Reply | Threaded
Open this post in threaded view
|

Re: chere problem with directories with single quote marks

Eric Blake (cygwin)
Eric Blake <ebb9 <at> byu.net> writes:
>
> Sorry, but I don't know ANY portable construct that works in all 4 cygwin
> shells (ash, bash, zsh, and pdksh).
>
> Plus there is still the matter of translating a valid command line into a
> registry entry that Windows can parse; I don't know if you can embed
> newlines, and without embedded newlines, a here-doc will not work.
>
> All I can do is wish you good luck.

I put a bit more thought into it, and verified that the following works from
the command line in all four shells (in other words, since here-docs inside
command substitutions are buggy, put the here-doc in a function and just call
the function in the command substitution):

$ cd /tmp; mkdir -p 'a'\''b`c)d  e$f'
$ foo(){ cat<<\EOF
> a'b`c)d  e$f
> EOF
> };cd "$(foo)"
$ pwd
/tmp/a'b`c)d  e$f
$

One other worry - a here-doc will fail if the delimiter happens to match the
filename.  When Windows expands %L, is it to an absolute pathname?  Otherwise,
I am afraid that if you use EOF, chere would fail to work in a directory named
EOF.  But even that can be worked around - since " is not valid in Windows
filenames, you could use this as an unambiguous here-doc inside your function:

cat<<\"
%L
"

--
Eric Blake




--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

Reply | Threaded
Open this post in threaded view
|

Re: chere problem with directories with single quote marks

Dave-50
In reply to this post by Eric Blake (cygwin)
--- Eric Blake wrote:

> According to Dave on 1/3/2006 2:03 PM:
> >>
> >>the here-doc correctly preserved the input string.  So applying that to
> >>the above problem, the registry entry MIGHT work (untested by me) if it is
> >>written as:
> >>
> >>SHELL_CMD="-l -c \\\"xargs -0 cd << 'EOF'\n%L\nEOF\nexec $SHELL_EXE\\\""
> >
> >
> > Hmmm. It appears that I haven't handled this case consistently. I'll have a
> look
> > at getting both ' and $ to work properly.
>
> Scratch my above example; cd is a shell builtin, so it won't work from

<snip>

Thanks for trying things, but...

The original poster is using the -1 option which attempts to get to the
appropriate directory without executing the intermediate script (xhere). As
you've seen this has problems with quoting which are unique to each of the
shells, since it is the shell that is evaluating the argument. This method also
has problems accessing network paths and starting ash and tcsh as noted on the
man page.

I've tested the other start option (-2), and that correctly goes to the path
"\\Minime\$@dave's `stuff". That contains an apostrophe, a backtick and what
could be interpreted as a shell parameter, all on a network path. I'm not
entirely sure why this works, but I suspect it has to do with the lack of
recursive parameter expansion. But don't quote me on that :)

Since the single quotes prevent shell expansion and things, I think that they
are most appropriate for the -1 option. I will note the limitation on entering
directories containing apostrophes in the man page.

The -2 option is the default, so I don't see this being a major issue.


Regards,

Dave.


               
__________________________________________
Yahoo! DSL – Something to write home about.
Just $16.99/mo. or less.
dsl.yahoo.com



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/