* lisp/ob-shell.el (org-babel-execute:shell)
(org-babel-sh-evaluate): Use the exit code as the value and,
consequently, as the result when no :results header is set.
See this thread:
https://orgmode.org/list/CA+A2iZaziAfMeGpBqL6qGrzrWEVvLvC0DUw++T4gCF3NGuW-DQ@mail.gmail.com/
And Tim's useful summary here:
https://orgmode.org/list/87sgiszqc1.fsf@gmail.com/
This commit resolves the issue by deciding not to make an exception
for ob-shell.el:
- the "value" of executing a shell/bash script is the exit code
- when no :results header is set, use the value as the result
- use :results output to use the stdout
* lisp/ob-shell.el (org-babel-sh-evaluate): Return the output
by default. Return exit status as the "value" when :result is
explicitely set to "value".
* lisp/ob-shell.el
(org-babel-shell-return-value-is-exit-status): Delete option.
* doc/org-manual.org (Collection): Be more accurate.
See the whole thread here:
https://lists.gnu.org/archive/html/emacs-orgmode/2020-02/msg00715.html
Thanks to everyone in this discussion.
* lisp/ob-shell.el
(org-babel-shell-return-value-is-exit-status): Rename from
`ob-shell-return-value-is-exit-status'.
(org-babel-execute:shell, org-babel-sh-evaluate): Use new name.
(org-babel--variable-assignments:bash_assoc): Fix indentation.
* lisp/ob-shell.el (ob-shell-return-value-is-exit-status): New
option.
(org-babel-execute:shell, org-babel-sh-evaluate): Use it.
In a shell source code block, when there is no :results header or when
the :results header is "value", the code block should return the value
of the source block, called in "functional mode", i.e. with the code
being called as a function and returning a value. See this part of
the manual:
‘value’
Default. Functional mode. Org gets the value by wrapping the code
in a function definition in the language of the source block. That
is why when using ‘:results value’, code should execute like a
function and return a value. For languages like Python, an
explicit ‘return’ statement is mandatory when using ‘:results
value’. Result is the value returned by the last statement in the
code block.
Strictly speaking, the "return value" of a shell source code block
should be the exit status of the last command in the block. As the
manpage for bash says: "the return value of a simple command is its
status".
This patch allows this strict interpretation of "value" for shell
blocks, while sticking to the current behavior of returning the shell
output of the code block.
Thanks to Vladimir Nikishkin for asking a question about this and to
Eric Fraga and Tim Cross for their inputs on this issue.
* lisp/ob-shell.el (org-babel--variable-assignments:bash): Do not
error when value is a list.
* testing/lisp/test-ob-shell.el (ob-shell/simple-list): New test.
Reported-by: Keith Amidon <camalot@picnicpark.org>
<http://permalink.gmane.org/gmane.emacs.orgmode/113920>
* lisp/ob-shell.el (org-babel-shell-initialize): Provide bindings to
handle variable assignments for all the supported shells.
(org-babel--variable-assignments:sh-generic):
(org-babel--variable-assignments:bash_array):
(org-babel--variable-assignments:bash_assoc):
(org-babel--variable-assignments:bash): Rename using an internal
naming scheme since they are not meant to be called directly from
"ob-core.el".
(org-babel-variable-assignments:shell): Apply renaming.
Reported-by: David Dynerman <emperordali@block-party.net>
<http://permalink.gmane.org/gmane.emacs.orgmode/111139>
* lisp/ob-shell.el (org-babel-shell-initialize): New function
(org-babel-shell-names): Properly update execute functions whenever the
variable is modified outside the Customize interface.
Protect apostrophes not covered by the last backport. Convert
expressions like '(...) to \\='(...) and symbols written as 'name to
`name'. (In addition to ensuring the correct display, the latter also
improves consistency with many Org docstrings.)
If these aren't protected, Emacs 25 may display them as curved quotes in
the help buffer, depending on the value of text-quoting-style.
* lisp/ob-shell.el (org-babel-sh-evaluate):
* lisp/org-clock.el (org-x11idle-exists-p): Do not use last
`call-process-shell-command' arg.
* lisp/org-mouse.el (org-mouse-show-context-menu): Ignore
`redisplay-dont-pause'.
* lisp/org.el (org-icompleting-read): Fix typo. Small refactoring.
* lisp/ob-shell.el (org-babel-sh-initiate-session): After initiating a
session, initialize the marker `comint-last-output-start' since it
is going to be used by the ANSI color filter without further checks
in Emacs 23 and throws an error.
* lisp/ob-shell.el: Remove defcustom `org-babel-sh-command' and
replace with `shell-file-name' throughout.
(org-babel-variable-assignments:sh): Make check for bash work in more
cases.
The original code and the patched version rely on the shell being
available via PATH. Instead the shell name should be mapped to the
appropriate executable via an alist and invoked via an absolute
filename. For security reasons the permissible shells should probably
be taken from /etc/shells or equivalent by default. Instead of
checking for bash, the same or another alist could provide the
information of whether or not the shell supports arrays (which indeed
were introduced by ksh originally).
* lisp/ob-shell.el: Remove unused defcustom
`org-babel-sh-var-quote-fmt'.
(org-babel-variable-assignments:bash_array):
(org-babel-variable-assignments:bash_assoc): Remove superfluous
`mapcar' and double quotes around parameters.
(org-babel-sh-var-to-sh): Single-quote the whole string and escape
all single quotes in the original string.
* lisp/ob-shell.el: added support to serialize vars as arrays or associative arrays as appropriate if it is using bash.
* testing/examples/ob-shell-test.org: a file containing a few code blocks both illustrating the use of arrays as well as serving as test for the new export functionality.
* testing/lisp/test-ob-shell.el: added a few unit tests that verify that this new logic only triggers for bash and no other shell at this time.
When variables are defined in a 'sh' code block, they are exported as strings. when the variable itself is an array or a table, then we simply get a shell variable that contains the list of all values in a non-structured form.
When calling the code block with bash, however, it will now export the list as an array, the table as an associative array. A scalar is exported the same way as before.
Signed-off-by: Pascal Fleury <fleury@google.com>
* lisp/ob-sh.el (org-babel-variable-assignments:sh): Check for
":hlines yes" and use header arg :hlines-string if
defined (default to "hline") and add this to the call of
`org-babel-sh-var-to-sh'.
(org-babel-sh-var-to-sh, org-babel-sh-var-to-string): Add additional
optional string argument `hline' and use it for the :hline parameter
in the call to `orgtbl-to-generic'.
* lisp/ob-shell.el (org-babel-execute:shell): Pass the cmdline header
argument to `org-babel-sh-evaluate'.
(org-babel-sh-evaluate): Pass the cmdline header argument to
`call-process-shell-command'.