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

From: Chris F.A. Johnson (c.f.a.johnson_at_rogers.com)
Date: 09/30/03


Date: 30 Sep 2003 07:05:14 GMT

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


Relevant Pages

  • Re: Are vbscript classes fast?
    ... Generally speaking, there is an overhead cost to creating a new scope, be it a function or a class, but the mere act of creating the scope is fairly rapid. ... I compared a generic function that just returned an empty value written in script and written as a method of a compiled component, and not surprisingly, the script function was slower by a factor of two - most likely due to scope creation. ... The MOST expensive way to create an object is to use WScript.CreateObject or Server.CreateObject instead of the native CreateObject in VBScript. ...
    (microsoft.public.scripting.vbscript)
  • Re: Create role on 64 bit extremely slow
    ... working properlly (except role creation), except that any change in a role ... made the whole AS server slow/ not responding (also other databases). ... generate the script and execute the script. ...
    (microsoft.public.sqlserver.olap)
  • Re: Copying the Latest FIle in a Directory in Win 2000/2003
    ... >>> Windows' default scheduler. ... >> batch script, since your requirement is to use the later of the created OR ... > assume that the modified date could not precede the creation date, ... > dates in a sortable format, like yyyy-mm-dd and times in 24hour format with ...
    (microsoft.public.windows.server.scripting)
  • Re: How to test the presence of a file and the date of its creation?
    ... there creation date. ... If the file is not present, the program stops. ... Here my script. ... There is no command called 'Exit'; ...
    (comp.unix.shell)
  • Re: annoying cut and paste behavior in query analyzer
    ... brackets, verbose collation - whatever... ... Our first-commandment in our shop is to script everything. ... INSERT's, INDEX creation, table creation - STORED PROC creation. ... >> SQL Server MVP ...
    (microsoft.public.sqlserver.server)