From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ihor Radchenko Subject: Re: Is it possible to pass variable to variables of src block? Date: Tue, 12 Dec 2017 15:17:11 +0800 Message-ID: <87fu8gwh3c.fsf@yantar92-laptop.i-did-not-set--mail-host-address--so-tickle-me> References: <877eu0gq3p.fsf@luisa.c0t0d0s0.de> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41079) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eOepN-0000Fx-Sv for emacs-orgmode@gnu.org; Tue, 12 Dec 2017 02:18:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eOepI-0002DY-Ii for emacs-orgmode@gnu.org; Tue, 12 Dec 2017 02:18:09 -0500 Received: from mail-it0-x233.google.com ([2607:f8b0:4001:c0b::233]:44292) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eOepI-0002DL-Cg for emacs-orgmode@gnu.org; Tue, 12 Dec 2017 02:18:04 -0500 Received: by mail-it0-x233.google.com with SMTP id b5so22160172itc.3 for ; Mon, 11 Dec 2017 23:18:04 -0800 (PST) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Xi Shen , Michael Welle Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hi David, One thing you can do is to make a code block, which will generate another code block, running your script with different arguments. Let me illustrate with a simple example: #+name: printecho #+BEGIN_SRC sh :var a=3D1 echo $a; #+END_SRC #+name: genscript #+BEGIN_SRC sh :var cmd=3D"printecho" :results raw output :wrap "src sh :n= oweb yes :results output" echo "cat << EOF" for x in "1" "2" "3" "4" "5" "6" "something"; do echo "<<$cmd(a=3D\"$x\")= >>"; done #+END_SRC #+RESULTS: genscript #+BEGIN_src sh :noweb yes :results output cat << EOF <> <> <> <> <> <> <> #+END_src #+RESULTS: : 1 : 2 : 3 : 4 : 5 : 6 : something Hope it helps. P.S. Does anyone know why the following does not evaluate noweb recursively? #+BEGIN_SRC sh :noweb yes :results output=20 <> #+END_SRC Regards, Ihor Xi Shen writes: > Hi Michael, > > Yes, I think this is a way to my previous question. But what I really want > to achieve is to loop through a list of server names and execute a script > on them. > > Say I have 20 different database server. How can I do a loop with each > server? > > > Regards, > David > > > On Wed, Dec 6, 2017 at 5:34 PM Michael Welle wrote: > >> Hello, >> >> Xi Shen writes: >> >> > Hi, >> > >> > http://orgmode.org/manual/var.html >> > >> > This wiki explains how to use variable inside a src block. But I wonder >> if >> > it is possible to specify variable to the variables in the src >> definition. >> > >> > E.g. for the sql src block, I want to execute a script on different >> server. >> > I want to define a variable for the ":dbhost" variable. >> did you think about something like this? >> >> >> (setq hmw/dbhost "db1") >> >> #+BEGIN_SRC sql :dbhost (symbol-value 'hmw/dbhost) :dbuser weather >> :database environment :engine postgresql >> select time, temperature from weather limit 20; >> #+END_SRC >> >> Regards >> hmw >> >> =2D-=20 Ihor Radchenko, PhD Student Singapore University of Technology and Design, 8 Somapah Road Singapore 487372 Email: yantar92@gmail.com, ihor_radchenko@mymail.sutd.edu.sg Tel: +6584017977 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEERZAHPFbUe3JemmzmZHB2Kn2hHYsFAlovgngACgkQZHB2Kn2h HYvqUAf/XCGscnzIpI2+U7KZz6Al2WAYghgt3QAYYYtzF97ZP5GTGxeHMds3cAJ5 5IiV5PHDqnuCgZFc/XZ4IH4WmgJRdGVx/z8IwASaiuHLyocoCT6FCy9K1q0+P7Ne 08Gg2DPkH8TD5DME5sEHs+Gmltt4a6XfxEsICScl8o18wTqoF5mrobN82gPghtNO Hizjzl89ZzRCFCbU8mlvPMrVOc/U8goyhbvQe6BLWMKxUw9KuFzqtdADwmDXncyp kYu/ZiMd667lt8YnOkmuymbl4sjULqHRVLddasGw56xjiUFGxwMOQCAHA8+Rx63+ qxv6DkXVTNsscXqigEEK4K/1K6Cpfw== =4Ysn -----END PGP SIGNATURE----- --=-=-=--