Zsh Mailing List Archive
Messages sorted by:
RE: (feature request) Shell script within shell script
- X-seq: zsh-users 5857
- From: "Clifford Caoile" <piyokun@xxxxxxxxx>
- To: "William Park" <opengeometry@xxxxxxxx>
- Subject: RE: (feature request) Shell script within shell script
- Date: Sun, 2 Feb 2003 00:48:01 +0900
- Cc: <zsh-users@xxxxxxxxxx>
- Importance: Normal
- In-reply-to: <20030201073655.GA3893@xxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
I am not an expert, but I was exploring here documents in bash and zsh just
this last week. Let me see if I get this right:
In zsh-4.0.x, you can use "here documents" or "here-strings". A here
document has this syntax (note there is no double quotations necessary):
>> /etc/hosts <<EOF
This adds the line to the /etc/hosts file. The cat command is implicit.
(It's still a useless cat trick, right?)
A "here string" uses the <<< construct, but I have not used this. Please
check the docs.
You can also strip indentation by typing "<<-" instead of just "<<".
There is also interpretation done within the here document. This has bitten
me a couple of times. Remember in a bash or zsh here document that the '$'
(dollar sign), '\' (backslash) and the '`' (backquote) are interpreted even
inside a here document, so you must prepend a backslash, i.e. '\$' and '\\'
and '\`'. This make the here document look gastly horrid. You mention you
will be using Awk/Python/Perl/etc. I know that Perl uses $ a lot. Also Awk?
What you will be typing will not be easy to keep track because zsh silently
substitutes text. Debugging will be hard. Is it possible to turn this off?
Of course, you could always try to construct your foreign language script
line by line. That is what I did before, like this:
echo '#! /usr/bin/perl' >> $tmpcmdfile
chmod 700 $tmpcmdfile
Do you like typing? ;-) This example actually led me to exploring here
Specifically with your example, I am unable to ascertain what you want to
do. Do you want to execute that here document on the line where you declare
it? What does that "herefile" mean? Is that syntactic sugar meaning "foreign
language eval?" In any event, I do not know how to do that, and I don't
think that's a zsh-4.0.x capability.
Can a real expert answer please? ;-)
< ^ ; ~, Clifford Escobar CAOILE (aka "Piyo-kun")
J~~> _.___...:.__..__.: __.:_. .:_.__::_..:._::._... _____ p(^_^)q
| -----Original Message-----
| From: William Park [mailto:opengeometry@xxxxxxxx]
| Sent: Saturday, February 01, 2003 16:37
| To: zsh-users@xxxxxxxxxx
| Subject: Re: (feature request) Shell script within shell script
| 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
| herefile test2 << "EOF"
| #! /usr/bin/python
| 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?
| William Park, Open Geometry Consulting, <opengeometry@xxxxxxxx>
| Linux solution for data management and processing.
Messages sorted by: