emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [PATCH] Re: [BUG] ob-shell: :shebang changes interpretation of :cmdl


From: Max Nikulin
Subject: Re: [PATCH] Re: [BUG] ob-shell: :shebang changes interpretation of :cmdline
Date: Tue, 23 Apr 2024 17:51:30 +0700
User-agent: Mozilla Thunderbird

On 21/04/2024 22:09, Matt wrote:
The proposed solution assumes we intend to parse the characters
following :cmdline as space delimited and grouped by quotes.  However,
AFAICT, the parsing issue makes this solution ambiguous.

Matt, I am sorry, but I do not agree with your proposal. I do not think that `split-string-and-unquote' will solve all issues.

Certainly issues with formatting of output should be treated separately.

I figured out there is at least one more issue. Consider

#+property: header-args:bash :results verbatim
#+begin_src bash :cmdline $LANG :shebang #!/bin/bash
  printf '"%s" ' "$0" "$@"
  printf '\n'
  tr '\000' '\n' </proc/$$/cmdline
#+end_src

#+RESULTS:
: "/tmp/babel-Is56Ki/sh-script-8FluOx" "$LANG"
: /bin/bash
: /tmp/babel-Is56Ki/sh-script-8FluOx
: $LANG

#+begin_src bash :cmdline $LANG
  printf '"%s" ' "$0" "$@"
  printf '\n'
  tr '\000' '\n' </proc/$$/cmdline
#+end_src

#+RESULTS:
: "/tmp/babel-Is56Ki/sh-script-g0cQ7R" "en_GB.UTF-8"
: /usr/bin/bash
: -c
: /tmp/babel-Is56Ki/sh-script-g0cQ7R $LANG

First line is argv as it is represented for a script, next lines are exec arguments at lower level (actual executable may be obtained from
"readlink /proc/$$/exe")

Notice that in the former case "$LANG" is passed literally, but in the latter it is expanded. I am in favor of dropping `shell-command-switch' in the latter case to pass arguments literally in both cases.

I think, it would be more consistent with :var to specify multiple arguments using elisp lists
#+header: :cmdline '("first 1" "second 2")

However looking wider, I do not like that :cmdline for ob-shell has different meaning than for other languages, see e.g. ob-sql. Only for shell this parameter is treated as arguments of a *script*. In other cases :cmdline is used to specify arguments of *interpreter* and I think ob-shell should follow this convention.

Actually script arguments (and :stdin) might be applied to python and at least some other languages, so support of this feature should be moved from ob-shell to common org-babel code.

My point:
- header arguments should have as close as possible meaning across various languages. - withing ob-shell variation of ways to execute a script should be minimized either some parameters (:cmdline, :shebang, :stdin) are specified or not.

Finally a note on tests
+(ert-deftest test-cmdline-alone-and-with-shebang-have-same-result ()
+  "Pass arguments to a block.  Don't use shebang.  Then use
+shebang set to the same language as the block.  The result should
+be the same."
+  (should (equal
+           (org-test-with-temp-text
+               "#+begin_src bash :cmdline 1 2 3
+echo \"$1\"
+<point>
+#+end_src"
+             (org-babel-execute-src-block))
+           (org-test-with-temp-text
+               "#+begin_src bash :cmdline 1 2 3 :shebang #!/usr/bin/env bash
+echo \"$1\"
+<point>
+#+end_src"
+             (org-babel-execute-src-block)))))
I believe, that starting point of the discussion is that the results should be same and decision what is more correct is the result of the discussion. Unit tests should check both cases independently and should fix particular treatment of arguments.




reply via email to

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