Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: (feature request) Shell script within shell script



On Sat, Feb 01, 2003 at 02:36:55AM -0500, William Park wrote:
> Dear Zsh expert,
> 
> When writing a shell script, quite often, I have to write bunch of
> separate Awk/Python/Perl/etc scripts that are more than few lines.  I
> tend to lose track of which script does what, and get bitten over two
> levels of quotes.
> 
> Essentially, I wish I could do something like
>     
>     herefile test1 << "EOF"
>     #! /usr/bin/gawk -f
>     ...
>     ...
>     EOF
> 
> and
> 
>     herefile test2 << "EOF"
>     #! /usr/bin/python
>     ...
>     ...
>     EOF
> 
> so that invocation and usage of 'test1' and 'test2' will be the same as
> if they were separate real files.
> 
> Can Zsh do this now?  If not, does Zsh have standard mechanism to
> provide this kind of extensions?


I've finally managed to find a solution.  It's called "process
substitution":
    function test1 () {
	awk -f <( cat <<"EOF"
	    ...
	    ...
	EOF
	)
    }
and
    function test2 () {
	python <( cat <<"EOF"
	    ...
	    ...
	EOF
	)
    }

-- 
William Park, Open Geometry Consulting, <opengeometry@xxxxxxxx>
Linux solution for data management and processing. 



Messages sorted by: Reverse Date, Date, Thread, Author