emacs-orgmode
[Top][All Lists]
Advanced

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

Re: Noweb Function's body without evaluation


From: Ihor Radchenko
Subject: Re: Noweb Function's body without evaluation
Date: Tue, 04 Apr 2023 12:14:01 +0000

suarezmiguelc@icloud.com writes:

> #+name: getClientInstanceNameNew
> #+begin_src shell :session something :var connection="admin@10.0.3.149" :var 
> client="example_client" :var apacheDir="/etc/apache/vhosts"
> <<initSSH>>
> client=$client
> apacheDir=$apacheDir
> grep $client $apacheDir/*
> #+end_src
>
> So, the initSSH call works successfully, so that concludes my first question, 
> being that I can now affect the $connection variable. Thank you again!
>
> However, since the SSH call changes the environment, the $client and 
> $apacheDir variables are not defined in the new environment. I did try 
> setting it again like above, but this doesn’t help as the variables do not 
> exist.

Org babel knows not if the environment changes along the way.
Of course, you can break the variable in bash by calling "bash" as one of
the commands in src block. Or you can do more crazy staff and call
"python" (or, say, "ghci") interpreter. There is no sane way to handle
such weird scenarios programmatically.

I suggest you to write some kind of wrapper like

#+name: obl-identity
#+begin_src emacs-lisp :var x=""
x
#+end_src

#+begin_src bash :noweb yes
<<initSSH>>
client=<<obl-identity(x="example_client")>>
#+end_src

This will not rely on language-specific way to define variables and
instead generate the code you want to execute fully, on Elisp side.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>



reply via email to

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