unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Shell argument quoting woes
@ 2013-07-25 13:30 Thorsten Jolitz
  0 siblings, 0 replies; 4+ messages in thread
From: Thorsten Jolitz @ 2013-07-25 13:30 UTC (permalink / raw)
  To: help-gnu-emacs


Hi List, 

assume this works in a shell

,------------------------
| $ prg -'fun "strg" num'
`------------------------

with 'prg' being a shell-command (for bash on GNU/Linux) calling a program,
'fun' being a function defined in that program, 'strg' being a string argument
to that function, and 'num' being a numeric argument to that function.

The task is to make a string out of this in an Elisp program and give
this 'cmd' as single argument to an Elisp function that then does
something like

#+begin_src emacs-lisp
(let ((cmdlist (split-string cmd)))
  (set-buffer (apply 'make-comint "buffer-name" (car cmdlist)
                     nil (cdr cmdlist) ) ))
#+end_src

Experimenting with (format "%s %S etc" ...) and (shell-quote-argument..) did
not result in anything that works. It seems the outcome is either

,--------------------
| prg -'fun strg num'
`--------------------

or

,------------------------
| prg -'fun \"strg\" num'
`------------------------

or

,--------------------------------
| prg\\ -\\'fun\\ \\\"strg\\\"\\ num\\'
`--------------------------------

or something similar, all resulting in errors.

Trying to replace the single quotes in that line with double-quote did not
work either.

How can I quote such a 'cmd' string in a way that it finally arrives as

,------------------------
| $ prg -'fun "strg" num'
`------------------------

?

-- 
cheers,
Thorsten




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Shell argument quoting woes
       [not found] <mailman.1758.1374759057.12400.help-gnu-emacs@gnu.org>
@ 2013-07-25 14:51 ` Rustom Mody
  2013-07-25 15:28   ` Thorsten Jolitz
       [not found]   ` <mailman.1765.1374766754.12400.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 4+ messages in thread
From: Rustom Mody @ 2013-07-25 14:51 UTC (permalink / raw)
  To: help-gnu-emacs

On Thursday, July 25, 2013 7:00:32 PM UTC+5:30, Thorsten Jolitz wrote:
Seems to me that this inside lisp

> ,------------------------
> | prg -'fun \"strg\" num'
> `------------------------
> How can I quote such a 'cmd' string in a way that it finally arrives as

should be this

> 
> ,------------------------
> | $ prg -'fun "strg" num'
> `------------------------

at the shell... No?

Anyway heres some (not too great) hacking:
(with my recently learnt from Bastien's C-j!) 

(setq cmd "prg -'fun \"strg\" num'")
"prg -'fun \"strg\" num'"
(setq x (split-string cmd "-"))
("prg " "'fun \"strg\" num'")
(setq p (car (split-string (car x))))
"prg"
(setq arg (cadr x))
"'fun \"strg\" num'"
; (make-comint "buffer-name" p nil (concat "-" arg))



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Shell argument quoting woes
  2013-07-25 14:51 ` Shell argument quoting woes Rustom Mody
@ 2013-07-25 15:28   ` Thorsten Jolitz
       [not found]   ` <mailman.1765.1374766754.12400.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 4+ messages in thread
From: Thorsten Jolitz @ 2013-07-25 15:28 UTC (permalink / raw)
  To: help-gnu-emacs

Rustom Mody <rustompmody@gmail.com> writes:

> On Thursday, July 25, 2013 7:00:32 PM UTC+5:30, Thorsten Jolitz wrote:
> Seems to me that this inside lisp
>
>> ,------------------------
>> | prg -'fun \"strg\" num'
>> `------------------------
>> How can I quote such a 'cmd' string in a way that it finally arrives as
>
> should be this
>
>> 
>> ,------------------------
>> | $ prg -'fun "strg" num'
>> `------------------------
>
> at the shell... No?
>
> Anyway heres some (not too great) hacking:
> (with my recently learnt from Bastien's C-j!) 
>
> (setq cmd "prg -'fun \"strg\" num'")
> "prg -'fun \"strg\" num'"
> (setq x (split-string cmd "-"))
> ("prg " "'fun \"strg\" num'")
> (setq p (car (split-string (car x))))
> "prg"
> (setq arg (cadr x))
> "'fun \"strg\" num'"
> ; (make-comint "buffer-name" p nil (concat "-" arg))

I see, so the problem was actually the string-splitting by spaces and
not the quoting. Thanks!

-- 
cheers,
Thorsten




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Shell argument quoting woes
       [not found]   ` <mailman.1765.1374766754.12400.help-gnu-emacs@gnu.org>
@ 2013-07-25 16:46     ` Rustom Mody
  0 siblings, 0 replies; 4+ messages in thread
From: Rustom Mody @ 2013-07-25 16:46 UTC (permalink / raw)
  To: help-gnu-emacs

On Thursday, July 25, 2013 8:58:51 PM UTC+5:30, Thorsten Jolitz wrote:
> I see, so the problem was actually the string-splitting by spaces and
> not the quoting. Thanks!

Actually ideal would be to split on only 1st space(s).
In languages like python this is possible.
I guess you can do it with a regexp in elisp:

Python 2.7.5+ (default, Jun  2 2013, 21:21:29) 
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> cmd="prg -'fun \"strg\" num'"
>>> cmd.split(" ", 1)
['prg', '-\'fun "strg" num\'']


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-07-25 16:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.1758.1374759057.12400.help-gnu-emacs@gnu.org>
2013-07-25 14:51 ` Shell argument quoting woes Rustom Mody
2013-07-25 15:28   ` Thorsten Jolitz
     [not found]   ` <mailman.1765.1374766754.12400.help-gnu-emacs@gnu.org>
2013-07-25 16:46     ` Rustom Mody
2013-07-25 13:30 Thorsten Jolitz

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 read-only IMAP folder(s) and NNTP newsgroup(s).