emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ken Mankoff <mankoff@gmail.com>
To: suarezmiguelc@icloud.com
Cc: emacs-orgmode@gnu.org
Subject: Re: Noweb Function's body without evaluation
Date: Thu, 16 Mar 2023 00:16:39 -0400	[thread overview]
Message-ID: <87zg8dtjo8.fsf@t480.home> (raw)
In-Reply-To: <BEA019FB-CD6C-4CF9-80B4-7441EC2AADFD@icloud.com>

Hi,

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.

https://lists.gnu.org/archive/html/emacs-orgmode/2023-03/msg00251.html

  -k.

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
> example:
>
> #+name: initSSH
> #+begin_src shell :var connection=“admin@somehost"
>
> ssh -t miguel@host "sudo -u someuser ssh -t $connection 'sudo su'"
> #+end_src
>
> 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
>
> df
> #+end_src
>
> 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
> <<initSSH(connection=“admin@anotherhost”)>>
> <<getStorage>>
> #+end_src
>
>
> 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\!"
> #+end_src
>
> #+results: greeting
> #+begin_src sh
>
> hello, world\!
> #+end_src
>
> #+begin_src shell
> <<greeting(name="ss")>>
> #+end_src
>
>
> 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
> <<greeting[:body](name="Testingggg")>>
> #+end_src
>
> 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_eoe
> org_babel_sh_prompt> hello, Testingggg\!
> sh: hello,: command not found
> org_babel_sh_prompt> echo 'org_babel_sh_eoe'
> org_babel_sh_eoe
> org_babel_sh_prompt> 
>
> 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
> error.
>
> I can’t find much documentation about this, what is the correct syntax
> here?,
>
> Thank you!



  reply	other threads:[~2023-03-16  4:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-15 22:54 Noweb Function's body without evaluation suarezmiguelc
2023-03-16  4:16 ` Ken Mankoff [this message]
2023-03-16  7:56   ` suarezmiguelc
2023-04-02 10:06 ` Ihor Radchenko
2023-04-03 13:03   ` suarezmiguelc
2023-04-04 12:14     ` Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zg8dtjo8.fsf@t480.home \
    --to=mankoff@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=suarezmiguelc@icloud.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).