14

I'm experimenting with sourcing data from org-mode into my shell scripts and I've run across a weirdness:

#+tblname: simple-table
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |

#+name: work-with-simple-list-shell
#+begin_src shell :var tbl=simple-table
echo "$tbl"
#+end_src

#+RESULTS: work-with-simple-list-shell
: 1

#+name: work-with-simple-list-sh
#+begin_src sh :var tbl=simple-table
echo "$tbl"
#+end_src

#+RESULTS: work-with-simple-list-sh
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |

Any idea what is going on?

4
  • 1
    It seems like ob-sh is deprecated in favour of ob-shell ( As seen in this thread of the mailing list).
    – Daniel
    Sep 6, 2017 at 12:29
  • If they are only aliases to each other then why the difference in behaviour?
    – stsquad
    Sep 6, 2017 at 12:35
  • Something weird with your config. I don't see any difference in behaviour here. If I echo $SHELL, I get the same shell for both. Also, did you try C-c C-v I to check whether both src-blocks have the same header-args?
    – Daniel
    Sep 6, 2017 at 13:00
  • @dangom: hmm same set of header args save for Lang:shell vs Lang:sh and header-args:shell vs header-args:sh but both set to nil. $SHELL reports bash in both cases.
    – stsquad
    Sep 6, 2017 at 13:18

1 Answer 1

17

The difference is which shell gets called to evaluate your block. shell calls whatever your default shell is while sh calls /bin/sh specifically. Your default shell is probably bash, which is an extension of sh. echo $0 will tell you what executable your shell is running:

#+BEGIN_SRC shell
echo $0
#+END_SRC

#+RESULTS:
: /bin/bash


#+BEGIN_SRC sh
echo $0
#+END_SRC

#+RESULTS:
: sh

Any of the shells in org-babel-shell-names that is installed on your system will work.

2
  • I'm still confused as to why the input variable gets so munged. Is this bash doing something different with the variable?
    – stsquad
    Dec 29, 2017 at 9:59
  • Yes: the table is passed as a list - in the sh case, the list is basically mapconcat-ed into a string; in the bash case, the list is assigned to an (indexed) array (try echo ${tbl[@]} as the body of the code block).
    – NickD
    Feb 12, 2023 at 18:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.