From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17263 invoked from network); 1 Feb 2003 19:30:00 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 1 Feb 2003 19:30:00 -0000 Received: (qmail 22376 invoked by alias); 1 Feb 2003 19:29:38 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 5861 Received: (qmail 22369 invoked from network); 1 Feb 2003 19:29:38 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 1 Feb 2003 19:29:37 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [4.46.181.248] by sunsite.dk (MessageWall 1.0.8) with SMTP; 1 Feb 2003 19:29:37 -0000 Received: (from schaefer@localhost) by candle.brasslantern.com (8.11.6/8.11.6) id h11JTcZ07571 for zsh-users@sunsite.dk; Sat, 1 Feb 2003 11:29:38 -0800 From: "Bart Schaefer" Message-Id: <1030201192938.ZM7570@candle.brasslantern.com> Date: Sat, 1 Feb 2003 19:29:38 +0000 In-Reply-To: <20030201073655.GA3893@node1.opengeometry.net> Comments: In reply to William Park "Re: (feature request) Shell script within shell script" (Feb 1, 2:36am) References: <20030128042243.GA3888@node1.opengeometry.net> <20030128104034.GA6470@node1.opengeometry.net> <20030131204945.GA1189@node1.opengeometry.net> <20030201073655.GA3893@node1.opengeometry.net> X-Mailer: Z-Mail (5.0.0 30July97) To: zsh-users@sunsite.dk Subject: Re: (feature request) Shell script within shell script MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Feb 1, 2:36am, William Park wrote: } Subject: Re: (feature request) Shell script within shell script } } Essentially, I wish I could do something like } } herefile test1 << "EOF" } #! /usr/bin/gawk -f } ... } ... } EOF Effectively, what you want to do is create a temp file and then execute it. That's as simple as: herefile () { setopt localtraps noshwordsplit local tmp=${TMPPREFIX}HERE$$ trap "command rm -f $tmp" EXIT : >| $tmp || return chmod u=rwx,go-rwx $tmp || return cat >| $tmp || return $tmp $@ } Try it with this silly example: herefile <<\EOF #! /bin/ls -l EOF The tricky bit of course is that the redirection becomes the standard input of the "herefile" function, so your script will see end-of-file as soon as it starts running. You can avoid this by doing some file descriptor manipulations: _herefile () { setopt localtraps noshwordsplit local tmp=${TMPPREFIX}HERE$$ trap "command rm -f $tmp" EXIT : >| $tmp || return chmod u=rwx,go-rwx $tmp || return cat >| $tmp || return $tmp $@ <&3 3<&- } alias herefile='_herefile 3<&0' herefile /etc/HOSTNAME /etc/issue <<\EOF #! /usr/bin/perl -p BEGIN { print join("\n\t", 'Printing these files: ', @ARGV)."\n\n"; } EOF This of course has the drawback of always consuming file descriptor 3, so it may not work well with other scripts or functions that do lots of file-descriptor swapping. You can pick another descriptor number if you think it'll make collisions less likely. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net