f



How to script the creation of a text file, with 4/5 lines of text

Hello all,

I'm trying to script the creation of a file with a few lines of text.  The
thing is that this text contains special characters and filepaths.  For
example, the text file I want to create looks something like the following:

THIS = ( that )
PATH = ( /this/is/a/test/test.jar )
(${PATH}) -> (${THIS})
test....

This is what I get when I do the following:
# echo "THIS = ( that ) PATH = ( /this/is/a/test/test.jar ) (${PATH}) ->
(${THIS}) test...." > test.out
THIS: Undefined variable

Adding a '/' in front of the '$' doesn't help either:
# echo "THIS = ( that ) PATH = ( /this/is/a/test/test.jar ) (/${PATH}) ->
(/${THIS}) test...." > test.out
THIS: Undefined variable

I'm trying to do this within a script, so I can't use the following because
I need a ctrl-C to break:
cat > test.out
THIS = ( that )
PATH = ( /this/is/a/test/test.jar )
(${PATH}) -> (${THIS})
test....

Does anyone know how I get around this?  Thanks for any help you can give
me.

-Stephen


0
Stephen
9/30/2003 2:44:23 AM
comp.unix.misc 550 articles. 0 followers. underh20.scubadiving (150) is leader. Post Follow

1 Replies
477 Views

Similar Articles

[PageSpeed] 16

On Tue, 30 Sep 2003 at 02:44 GMT, Stephen Copp wrote:
> Hello all,
> 
> I'm trying to script the creation of a file with a few lines of text.  The
> thing is that this text contains special characters and filepaths.  For
> example, the text file I want to create looks something like the following:
> 
> THIS = ( that )
> PATH = ( /this/is/a/test/test.jar )
> (${PATH}) -> (${THIS})
> test....

#!/bin/sh
echo "THIS = ( that )
PATH = ( /this/is/a/test/test.jar )
(\${PATH}) -> (\${THIS})" > FILE

> This is what I get when I do the following:
> # echo "THIS = ( that ) PATH = ( /this/is/a/test/test.jar ) (${PATH}) ->

    Are you doing this as the superuser (root)? If so, DON'T!

> (${THIS}) test...." > test.out
> THIS: Undefined variable

    Are you using csh (or tcsh) for scripting? Again, DON'T.

    For reasons why not, see:

        <http://www.grymoire.com/Unix/CshTop10.txt>
        <http://www.grymoire.com/Unix/Csh.html#uh-0>
        <http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/>

    Use a Bourne-type shell for scripting (sh, bash, ksh, ash, zsh).

> Adding a '/' in front of the '$' doesn't help either:

    Why would it? The escape character is \.

> # echo "THIS = ( that ) PATH = ( /this/is/a/test/test.jar ) (/${PATH}) ->
> (/${THIS}) test...." > test.out
> THIS: Undefined variable
> 
> I'm trying to do this within a script, so I can't use the following because
> I need a ctrl-C to break:
> cat > test.out

   That will read stdin, not the succeeding lines in the file.

> THIS = ( that )
> PATH = ( /this/is/a/test/test.jar )
> (${PATH}) -> (${THIS})
> test....
> 
> Does anyone know how I get around this?  Thanks for any help you can give
> me.

    For information on writing shell scripts, you would do better in
    the comp.unix.shell newsgroup.

-- 
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2003, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License
0
Chris
9/30/2003 7:05:14 AM
Reply: