emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] org babel execute shell in sh?


From: Nick Dokos
Subject: Re: [O] org babel execute shell in sh?
Date: Mon, 12 Mar 2012 15:10:58 -0400

Eric Schulte <address@hidden> wrote:

> I just pushed up a patch which adds this behavior.  It does result in
> some odd new possibilities, such as the following.
> 
> #+begin_src sh :shebang #!/bin/cat
>   foo
> #+end_src
> 
> #+RESULTS:
> | #!/bin/cat |
> |            |
> | foo        |
> 

Maybe my settings are slightly different, but the new bits give me

,----
| #+begin_src sh :shebang #!/bin/cat
|   foo
| #+end_src
| 
| #+RESULTS:
| : foo
`----

They also give me sensible results with the original example:

,----
| #+begin_src sh :shebang #!/bin/bash
| for np in {1..32}
| do
|   echo $np
| done
| #+end_src
| 
| #+RESULTS:
| |  1 |
| |  2 |
| |  3 |
| |... |
| | 31 |
| | 32 |
`----

The only potentially confusing case I've found is the following:

,----
| #+begin_src sh
| #!/bin/bash
| for np in {1..32}
| do
|   echo $np
| done
| #+end_src
| 
| #+RESULTS:
| : {1..32}
`----

with the shebang as part of the script. I'd argue it's doing the right
thing however: if one remembers that sh is the default command, this is
equivalent to the command line invocation:

,----
| $ sh foo.sh
`----

where foo.sh contains

--8<---------------cut here---------------start------------->8---
#!/bin/bash
for np in {1..32}
do
  echo $np
done
--8<---------------cut here---------------end--------------->8---

and that too gives:

,----
| $ sh foo.sh
| {1..32}
`----

whereas

,----
| $ ./foo.sh
| 1
| 2
| 3
| ...
| 31
| 32
`----

In other words, sh does not interpret the shebang: that is only done
by the exec system call.

Nick




reply via email to

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