emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Max Nikulin <manikulin@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: [BUG] ob-shell: internal representation of cmdline arguments the same
Date: Wed, 1 May 2024 19:11:30 +0700	[thread overview]
Message-ID: <v0tbhi$lvg$1@ciao.gmane.io> (raw)
In-Reply-To: <87frv4cqa6.fsf@localhost>

On 29/04/2024 19:22, Ihor Radchenko wrote:
> Matt writes:
> 
>> #+begin_src bash :cmdline "1 2 3"
[...]
> To force quotes in the :cmdline one can do
> 
> #+begin_src bash :cmdline "\"1 2 3\""
> echo "$1"
> #+end_src

I consider it as a kind of pitfall inconsistent with DWIM concept. An 
idea of a kludge is below.

#+begin_src sh :cmdline "1 2 3" :results verbatim
   printf '%s\n' "$@"
#+end_src

#+RESULTS:
: 1 2 3

#+begin_src sh :cmdline 1 2 3 :results verbatim
   printf '%s\n' "$@"
#+end_src

#+RESULTS:
: 1
: 2
: 3

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 73fb70c26..efba97f2c 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -3363,7 +3363,7 @@ (defun org-babel-read (cell &optional 
inhibit-lisp-eval)
         ((save-match-data
             (and (string-match "^[[:space:]]*\"\\(.*\\)\"[[:space:]]*$" 
cell)
                  (not (string-match "[^\\]\"" (match-string 1 cell)))))
-         (read cell))
+         (propertize (read cell) 'org-babel-value 'quoted-string))
         (t (org-no-properties cell))))

  (defun org-babel--string-to-number (string)
diff --git a/lisp/ob-shell.el b/lisp/ob-shell.el
index 35d9e9376..77c3fe261 100644
--- a/lisp/ob-shell.el
+++ b/lisp/ob-shell.el
@@ -300,6 +300,9 @@ (defun org-babel-sh-evaluate (session body &optional 
params stdin cmdline)
  of the statements in BODY, if RESULT-TYPE equals `value' then
  return the value of the last statement in BODY."
    (let* ((shebang (cdr (assq :shebang params)))
+         (cmdline-quote
+          (and cmdline
+               (get-text-property 0 'org-babel-value cmdline) "\""))
           (async (org-babel-comint-use-async params))
          (results-params (cdr (assq :result-params params)))
          (value-is-exit-status
@@ -329,7 +332,9 @@ (defun org-babel-sh-evaluate (session body &optional 
params stdin cmdline)
                          nil
                          (if shebang (when cmdline (list cmdline))
                            (list shell-command-switch
-                                (concat (file-local-name script-file) 
" " cmdline)))))
+                                (concat (file-local-name script-file)
+                                        " " cmdline-quote cmdline
+                                        cmdline-quote)))))
                 (buffer-string))))
            (session                     ; session evaluation
              (if async






  reply	other threads:[~2024-05-01 12:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-28 13:27 [BUG] ob-shell: internal representation of cmdline arguments the same Matt
2024-04-29 12:22 ` Ihor Radchenko
2024-05-01 12:11   ` Max Nikulin [this message]
2024-05-01 14:02     ` Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='v0tbhi$lvg$1@ciao.gmane.io' \
    --to=manikulin@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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).