emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: shell-command - missing shell-quote-argument for program?


From: Lennart Borgman
Subject: Re: shell-command - missing shell-quote-argument for program?
Date: Sun, 15 Oct 2006 11:30:28 +0200
User-agent: Thunderbird 1.5.0.7 (Windows/20060909)

Eli Zaretskii wrote:
From: Andreas Schwab <address@hidden>
Cc: Eli Zaretskii <address@hidden>,
        Carsten Dominik <address@hidden>, address@hidden
Date: Sat, 14 Oct 2006 19:50:01 +0200

diff -c -r1.26 ada-xref.el
*** ada-xref.el    10 Feb 2006 09:00:31 -0000    1.26
--- ada-xref.el    11 Oct 2006 22:55:48 -0000
***************
*** 1916,1923 ****
       (set-buffer (get-buffer-create "*grep*"))
       (while dirs
     (insert (shell-command-to-string
!          (concat "egrep -i -h '^X|" regexp "( |$)' "
!              (file-name-as-directory (car dirs)) "*.ali")))
     (set 'dirs (cdr dirs)))

       ;;  Now parse the output
--- 1916,1926 ----
       (set-buffer (get-buffer-create "*grep*"))
       (while dirs
     (insert (shell-command-to-string
!          (concat "egrep -i -h '^X|"
!                          (shell-quote-argument regexp)
This is wrong, the argument is already enclosed in single quotes.

Actually, I think that using '..' quoting is wrong, because it assumes
a Posix shell.  I think this should be rewritten by removing the
single quotes and instead quoting (via shell-quote-argument) the
entire regexp that is the result of `(concat "^X|" regexp "( |$)")'.
Do you agree that this is more portable?

Also, I thought that the issue here was with quoting the elements of
the `dirs' list, since they are file names that could include embedded
whitespace and other characters special to the shell.

Btw, while we are at that, `egrep' might not work with the latest
versions of GNU Grep, where `egrep' is a shell script that requires
/bin/sh.  "grep -E" is better, I think.
Attached a new patch.
Index: lisp/progmodes/ada-xref.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/progmodes/ada-xref.el,v
retrieving revision 1.26
diff -c -r1.26 ada-xref.el
*** lisp/progmodes/ada-xref.el  10 Feb 2006 09:00:31 -0000      1.26
--- lisp/progmodes/ada-xref.el  15 Oct 2006 09:22:19 -0000
***************
*** 1916,1923 ****
        (set-buffer (get-buffer-create "*grep*"))
        (while dirs
        (insert (shell-command-to-string
!                (concat "egrep -i -h '^X|" regexp "( |$)' "
!                        (file-name-as-directory (car dirs)) "*.ali")))
        (set 'dirs (cdr dirs)))
  
        ;;  Now parse the output
--- 1916,1927 ----
        (set-buffer (get-buffer-create "*grep*"))
        (while dirs
        (insert (shell-command-to-string
!                (concat
!                   "grep -E -i -h "
!                   (shell-quote-argument (concat "^X|" regexp "( |$)"))
!                   " "
!                   (shell-quote-argument (file-name-as-directory (car dirs)))
!                   "*.ali")))
        (set 'dirs (cdr dirs)))
  
        ;;  Now parse the output

reply via email to

[Prev in Thread] Current Thread [Next in Thread]