emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [babel] shell does not unquote
@ 2014-02-05  5:49 Samuel Wales
  2014-02-06  0:49 ` Eric Schulte
  0 siblings, 1 reply; 8+ messages in thread
From: Samuel Wales @ 2014-02-05  5:49 UTC (permalink / raw)
  To: emacs-orgmode

i don't know why the shell does not unquote here:

#+BEGIN_SRC sh :results verbatim output :var how="a 'b' \c \"d\" e"
:var dothis="echo \"hi\""
      echo $how
      $dothis
#+END_SRC

#+RESULTS:
#+begin_example
a 'b' c "d" e
"hi"
#+end_example

thanks.

samuel

-- 
The Kafka Pandemic: http://thekafkapandemic.blogspot.com

The disease DOES progress.  MANY people have died from it.  ANYBODY can get it.

Denmark: free Karina Hansen NOW.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [babel] shell does not unquote
  2014-02-05  5:49 [babel] shell does not unquote Samuel Wales
@ 2014-02-06  0:49 ` Eric Schulte
  2014-02-06  8:28   ` Samuel Wales
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Schulte @ 2014-02-06  0:49 UTC (permalink / raw)
  To: Samuel Wales; +Cc: emacs-orgmode

Use org-babel-expand-block (C-c C-v v) to view the code block with the
variable expansion.

Best,

Samuel Wales <samologist@gmail.com> writes:

> i don't know why the shell does not unquote here:
>
> #+BEGIN_SRC sh :results verbatim output :var how="a 'b' \c \"d\" e"
> :var dothis="echo \"hi\""
>       echo $how
>       $dothis
> #+END_SRC
>
> #+RESULTS:
> #+begin_example
> a 'b' c "d" e
> "hi"
> #+end_example
>
> thanks.
>
> samuel

-- 
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [babel] shell does not unquote
  2014-02-06  0:49 ` Eric Schulte
@ 2014-02-06  8:28   ` Samuel Wales
  2014-02-06 20:12     ` Eric Schulte
  0 siblings, 1 reply; 8+ messages in thread
From: Samuel Wales @ 2014-02-06  8:28 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode

hi eric,

say you want to list 2 files: "1 space" and "nospace".

#+call: list(how="\"1 space\" nospace")

#+name: list
#+BEGIN_SRC sh :noweb yes :results verbatim output
  {
      # this fails
      # ls $how
      # this would work, if there were a call option to support it
      # ls <<how>>
  } 2>&1
  :
#+END_SRC

is there?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [babel] shell does not unquote
  2014-02-06  8:28   ` Samuel Wales
@ 2014-02-06 20:12     ` Eric Schulte
  2014-02-06 21:55       ` Samuel Wales
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Schulte @ 2014-02-06 20:12 UTC (permalink / raw)
  To: Samuel Wales; +Cc: emacs-orgmode, Eric Schulte

Samuel Wales <samologist@gmail.com> writes:

> hi eric,
>
> say you want to list 2 files: "1 space" and "nospace".
>
> #+call: list(how="\"1 space\" nospace")
>
> #+name: list
> #+BEGIN_SRC sh :noweb yes :results verbatim output
>   {
>       # this fails
>       # ls $how
>       # this would work, if there were a call option to support it
>       # ls <<how>>
>   } 2>&1
>   :
> #+END_SRC
>
> is there?

You can't mix noweb and variable calling.  You could pass the files in
using either of the following techniques.

#+name: files-tab
| with space |
| nospace    |

#+name: files-ex
: with space
: nospace

#+name: list
#+begin_src sh :var files="" :results verbatim
IFS="
"
for file in $files;do
  echo "-|$file|-"
done
#+end_src

#+call: list(files-tab)

#+RESULTS:
: -|with space|-
: -|nospace|-

#+call: list(files-ex)

#+RESULTS:
: -|with space|-
: -|nospace|-

-- 
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [babel] shell does not unquote
  2014-02-06 20:12     ` Eric Schulte
@ 2014-02-06 21:55       ` Samuel Wales
  2014-02-07  2:13         ` Eric Schulte
  0 siblings, 1 reply; 8+ messages in thread
From: Samuel Wales @ 2014-02-06 21:55 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode

thanks for the examples, but they don't meet my needs as tables for
each set of arguments would be too unwieldy.

what would be ideal is to allow setting noweb expansions in the call
line (instead of requiring named blocks to provide the expansion).
i.e. it is similar to setting a var, but is a noweb setting instead.

then i would just do the call with the files i want, quoted the way i want.

may i make this a feature request?


On 2/6/14, Eric Schulte <schulte.eric@gmail.com> wrote:
> #+name: files-tab
> | with space |
> | nospace    |
>
> #+name: files-ex
> : with space
> : nospace
>
> #+name: list
> #+begin_src sh :var files="" :results verbatim
> IFS="
> "
> for file in $files;do
>   echo "-|$file|-"
> done
> #+end_src
>
> #+call: list(files-tab)
>
> #+RESULTS:
> : -|with space|-
> : -|nospace|-
>
> #+call: list(files-ex)
>
> #+RESULTS:
> : -|with space|-
> : -|nospace|-

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [babel] shell does not unquote
  2014-02-06 21:55       ` Samuel Wales
@ 2014-02-07  2:13         ` Eric Schulte
  2014-02-09  1:39           ` Samuel Wales
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Schulte @ 2014-02-07  2:13 UTC (permalink / raw)
  To: Samuel Wales; +Cc: emacs-orgmode

Samuel Wales <samologist@gmail.com> writes:

> thanks for the examples, but they don't meet my needs as tables for
> each set of arguments would be too unwieldy.
>

How about this.

#+name: list
#+begin_src sh :var files="" :results verbatim
IFS="
"
for file in $files;do
  echo "-|$file|-"
done
#+end_src

#+call: list("1 space\nnospace")

#+RESULTS:
: -|1 space|-
: -|nospace|-

>
> what would be ideal is to allow setting noweb expansions in the call
> line (instead of requiring named blocks to provide the expansion).
> i.e. it is similar to setting a var, but is a noweb setting instead.
>
> then i would just do the call with the files i want, quoted the way i want.
>
> may i make this a feature request?
>

I'm not sure that the additional utility justifies the added complexity.

Best,

>
>
> On 2/6/14, Eric Schulte <schulte.eric@gmail.com> wrote:
>> #+name: files-tab
>> | with space |
>> | nospace    |
>>
>> #+name: files-ex
>> : with space
>> : nospace
>>
>> #+name: list
>> #+begin_src sh :var files="" :results verbatim
>> IFS="
>> "
>> for file in $files;do
>>   echo "-|$file|-"
>> done
>> #+end_src
>>
>> #+call: list(files-tab)
>>
>> #+RESULTS:
>> : -|with space|-
>> : -|nospace|-
>>
>> #+call: list(files-ex)
>>
>> #+RESULTS:
>> : -|with space|-
>> : -|nospace|-

-- 
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [babel] shell does not unquote
  2014-02-07  2:13         ` Eric Schulte
@ 2014-02-09  1:39           ` Samuel Wales
  2014-02-10  3:18             ` Eric Schulte
  0 siblings, 1 reply; 8+ messages in thread
From: Samuel Wales @ 2014-02-09  1:39 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode

hi eric,

the object is to make the code inside a babel shell block as similar
to a real shell script as possible.  also, calling it using #+call
should be like calling it from another shell script.

this isn't possible in babel at present.

the script cannot use "$@" for its positional parameters.  it could
use <<noweb>>, but that requires the creation of an extraneous block
merely to do a call, instead of supplying the value in the call line.

if making this possible is not desirable, then i will not request it,
but i wanted to explain why this object is not achieved with existing
babel options that i am aware of.

thanks.

samuel

-- 
The Kafka Pandemic: http://thekafkapandemic.blogspot.com

The disease DOES progress.  MANY people have died from it.  ANYBODY can get it.

Denmark: free Karina Hansen NOW.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [babel] shell does not unquote
  2014-02-09  1:39           ` Samuel Wales
@ 2014-02-10  3:18             ` Eric Schulte
  0 siblings, 0 replies; 8+ messages in thread
From: Eric Schulte @ 2014-02-10  3:18 UTC (permalink / raw)
  To: Samuel Wales; +Cc: emacs-orgmode, Eric Schulte

Samuel Wales <samologist@gmail.com> writes:

> hi eric,
>
> the object is to make the code inside a babel shell block as similar
> to a real shell script as possible.  also, calling it using #+call
> should be like calling it from another shell script.
>
> this isn't possible in babel at present.
>
> the script cannot use "$@" for its positional parameters.  it could
> use <<noweb>>, but that requires the creation of an extraneous block
> merely to do a call, instead of supplying the value in the call line.
>

A couple of languages already support a :cmdline header argument.  I've
just added shell block support for :cmdline, so the following is now
possible.

#+begin_src sh :cmdline "foo bar baz"
echo $2
#+end_src

#+RESULTS:
: bar

>
> if making this possible is not desirable, then i will not request it,
> but i wanted to explain why this object is not achieved with existing
> babel options that i am aware of.
>

I hope the above is sufficient, if not I'm not personally able to do
much more on this front, although I'm always happy to review patches.

Best,

>
> thanks.
>
> samuel

-- 
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-02-10  3:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-05  5:49 [babel] shell does not unquote Samuel Wales
2014-02-06  0:49 ` Eric Schulte
2014-02-06  8:28   ` Samuel Wales
2014-02-06 20:12     ` Eric Schulte
2014-02-06 21:55       ` Samuel Wales
2014-02-07  2:13         ` Eric Schulte
2014-02-09  1:39           ` Samuel Wales
2014-02-10  3:18             ` Eric Schulte

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