[Top][All Lists]

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

Re: Noweb Function's body without evaluation

From: suarezmiguelc
Subject: Re: Noweb Function's body without evaluation
Date: Thu, 16 Mar 2023 08:56:21 +0100

Hello Ken, thank you for your message,

After reading the very interesting get_property function, I found that even though I will probably use it for some cases, it doesn’t apply directly, to my case.

For more examples, if I have 1 source code block:

#+name: greeting
#+begin_src sh :var name="world" :results output :session testing

echo "hello, $name\!"

I have three options in noweb to use this:
- Use its body into another begin_src source code block with <<greeting>>
- Use its result “hello, world!” Into another code block, which results in babel trying to execute the hello, command, which doesn’t exist, this with <<greeting()>>
- Use its result, the same as above, but with another parameter, results in the same but the variable name is different, so <<greeting(name=“another name”)>>

I’m trying to do the first, but with another parameter, so Use its body into another begin_src source code block with, get the resulting body after changing the variable without it being evaluated, so that I get a valid command to get to bash, like with <<greeting>>, but I can specify a different name variable.

I found the [:body] param but, even though it lets me change the variable as I want, it then tries to evaluate it, so I get a different value but the same hello, command doesn’t exist. Even though what I would want is to get echo “hello, $name\!” but, $name is different.

Thank you for your response Ken, I hope I gave a clearer example with the above.

16/3/23 5:16、Ken Mankoff <mankoff@gmail.com>のメール:


I'm not sure that I understand your issue or needs from the provided examples, but I wonder if the example I provide here would be helpful. It bypasses :var an lets you inject a PROPERTY value anywhere. It is also language agnostic. You can use it to execute commands (that are set as PROPERTY values) or set variables to values.



On 2023-03-15 at 18:54 -04, suarezmiguelc@icloud.com wrote...
Hello Org-mode community. I’m using Emacs Doom Framework, specifically:

Emacs 28.2 (build 1, aarch64-apple-darwin22.3.0, Carbon Version 169
AppKit 2299.4) of 2023-02-23.

I use heavily org-mode for Literate DevOps, so I have a lot of shell
commands that connect through SSH and do some things later, for

#+name: initSSH
#+begin_src shell :var connection=“admin@somehost"

ssh -t miguel@host "sudo -u someuser ssh -t $connection 'sudo su'"

So then I can call:

#+call: initSSH(connection=“admin@anotherhost”)

With any other header parameters or session, the above works
correctly. I cannot use tramp due to network latency issues, so this
is the most performance way for me, since I also have to do some
multi-hops which are indeed supported in tramp, but it is too slow for
me, so I rather only commands.

The thing is that, I then would like to call these not with a #+call
function, but add them into a bigger script, let’s say that I define
another command:

#+name: getStorage
#+begin_src shell


Which has to be run in a remote server, could be any remote server as
I have to connect to several. So I would like to be able to:

#+begin_src shell

The first doesn’t work as org-mode runs the code and passes the
resulting string to bash, which isn’t a command. The latter works
normally. So the issue here are the parameters.

So I made another simple example for this:

#+name: greeting
#+begin_src sh :var name="world" :results output :session testing

echo "hello, $name\!"

#+results: greeting
#+begin_src sh

hello, world\!

#+begin_src shell

This results in sh: hello,: command not found, as it is executing the function. I see in the documentation that I can:
- Call a function’s body with <<namedcodeblock>>
- Execute a function and return its results with <<namedcodeblock()>>
- Execute a function and return its results even with different params with <<namedcodeblock(param=“sds”)>>

So right now, the one that’s missing is, call a function’s body with different parameters. So the
function <<namedcodeblock>> is not evaluated.

After searching a lot, I came across:

#+begin_src shell :session testing

Which results in:

sh-3.2$ PS1="org_babel_sh_prompt> "
org_babel_sh_prompt> name='Testingggg'
org_babel_sh_prompt> echo "hello, $name\!"
hello, Testingggg\!
org_babel_sh_prompt> echo 'org_babel_sh_eoe'
org_babel_sh_prompt> hello, Testingggg\!
sh: hello,: command not found
org_babel_sh_prompt> echo 'org_babel_sh_eoe'

Which is somewhat what I need since at least the variable is changed,
but the result of this execution is also passed to shell so, same

I can’t find much documentation about this, what is the correct syntax

Thank you!

reply via email to

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