zsh-users
 help / color / mirror / code / Atom feed
* Adding arbitrary data at the end of a script
@ 2005-02-17  9:12 DervishD
  2005-02-17  9:36 ` Wayne Davison
  0 siblings, 1 reply; 3+ messages in thread
From: DervishD @ 2005-02-17  9:12 UTC (permalink / raw)
  To: Zsh Users

    Hi all :)

    I'm doing a self-contained script that needs some data to work.
This data is going to be added at the end of script (after the 'exit
0' command that terminates the script), but zsh reads *and tries to
expand* the entire bunch of data. I haven't found in SUS anything
that forbids or allows this behaviour, and I'm confused.

    The script is functionally like this:

#!/bin/zsh
true
exit 0
<Text data that contains some '$', backticks, etc.>

    I've tried this, too:

#!/bin/zsh
true
exit 0
cat << DATA.EOF > /dev/null
<Text data that contains some '$', backticks, etc.>
DATA.EOF

    Obviously, I can quote, by hand, all things that makes the shell
barf (not only Zsh, Bash suffer from this too), but I would like to
avoid it because it will be very time consuming and error prone. In
fact, the 'bunch of data' is no more than a shell script skeleton
that will be processed through sed. The main script uses something
like this:

cat 0 | sed...

    to process itself and the bunch of data and generate another
script.

    If I cannot avoid the data to be read by the shell, how can I
avoid expansion portably? The script must be self-contained, and the
data must go inside of it. I've thought of a solution but it's not
very good for me and I would like to avoid it: ASCII armoring the
'data' (removing the shell metachars in the process) and dearmoring
it on the fly while processing through sed...

    Thanks in advance :)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.dervishd.net & http://www.pleyades.net/
It's my PC and I'll cry if I want to...


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Adding arbitrary data at the end of a script
  2005-02-17  9:12 Adding arbitrary data at the end of a script DervishD
@ 2005-02-17  9:36 ` Wayne Davison
  2005-02-17 11:23   ` DervishD
  0 siblings, 1 reply; 3+ messages in thread
From: Wayne Davison @ 2005-02-17  9:36 UTC (permalink / raw)
  To: Zsh Users

On Thu, Feb 17, 2005 at 10:12:56AM +0100, DervishD wrote:
> #!/bin/zsh
> true
> exit 0
> cat << DATA.EOF > /dev/null
> <Text data that contains some '$', backticks, etc.>
> DATA.EOF

You just need single quotes around the DATA.EOF to tell zsh to treat the
data literally:

#!/bin/zsh
true
exit 0
cat << 'DATA.EOF' > /dev/null
<Text data that contains some '$', backticks, etc.>
DATA.EOF

You could drop the ">/dev/null" too, if you wanted (since the line will
never get executed).  You could even substitute another program for
"cat" (such as "true" or "MadeUpNameOfMissingCommand") if you want to
make the line more distinctive.

..wayne..


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Adding arbitrary data at the end of a script
  2005-02-17  9:36 ` Wayne Davison
@ 2005-02-17 11:23   ` DervishD
  0 siblings, 0 replies; 3+ messages in thread
From: DervishD @ 2005-02-17 11:23 UTC (permalink / raw)
  To: Wayne Davison; +Cc: Zsh Users

    Hi Wayne :)

 * Wayne Davison <wayned@users.sourceforge.net> dixit:
> On Thu, Feb 17, 2005 at 10:12:56AM +0100, DervishD wrote:
> > #!/bin/zsh
> > true
> > exit 0
> > cat << DATA.EOF > /dev/null
> > <Text data that contains some '$', backticks, etc.>
> > DATA.EOF
> You just need single quotes around the DATA.EOF to tell zsh to treat the
> data literally

    Wayne, thanks for showing me how utterly stupid I am O:))) I knew
about this feature, but I thought that it was a zsh thing, non
portable. I didn't even look that in SUS. I just looked a moment ago
to make sure it was non portable and SUS specifies just the same :((

    Well, thanks for your help because you're solved my problem. I
didn't even think about using this mechanism O:)

> You could drop the ">/dev/null" too, if you wanted (since the line will
> never get executed).  You could even substitute another program for
> "cat" (such as "true" or "MadeUpNameOfMissingCommand") if you want to
> make the line more distinctive.

    I think that I will substitute it with the name of the file that
must be generated so the filtering in the sed script is easier.

    Thanks a lot, Wayne :)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.dervishd.net & http://www.pleyades.net/
It's my PC and I'll cry if I want to...


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-02-17 11:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-17  9:12 Adding arbitrary data at the end of a script DervishD
2005-02-17  9:36 ` Wayne Davison
2005-02-17 11:23   ` DervishD

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).