ksh : printing a file to stdout with the variables expanded - Unix

This is a discussion on ksh : printing a file to stdout with the variables expanded - Unix ; I have a file with variables like ${VAR1} ${VAR2} etc embedded in it. Is there any way I can print this file to the stdout after expanding all the variables. Thanks --sony...

+ Reply to Thread
Results 1 to 5 of 5

Thread: ksh : printing a file to stdout with the variables expanded

  1. ksh : printing a file to stdout with the variables expanded

    I have a file with variables like ${VAR1} ${VAR2} etc embedded in it.
    Is there any way I can print this file to the stdout after expanding
    all the variables.

    Thanks
    --sony

  2. Re: ksh : printing a file to stdout with the variables expanded

    On Nov 16, 11:13 am, "sonyant...@hotmail.com"
    wrote:
    > I have a file with variables like ${VAR1} ${VAR2} etc embedded in it.
    > Is there any way I can print this file to the stdout after expanding
    > all the variables.
    >
    > Thanks
    > --sony


    I'm not sure what you really mean..

    Can you give more details ?

    like.. what exactly do you want to go "from" and "to"

    --Ben

  3. Re: ksh : printing a file to stdout with the variables expanded

    On 2007-11-16, sonyantony@hotmail.com wrote:
    >
    >
    > I have a file with variables like ${VAR1} ${VAR2} etc embedded in it.
    > Is there any way I can print this file to the stdout after expanding
    > all the variables.


    eval "printf '%s\n' \"$( < FILE )\""

    --
    Chris F.A. Johnson, author |
    Shell Scripting Recipes: | My code in this post, if any,
    A Problem-Solution Approach | is released under the
    2005, Apress | GNU General Public Licence

  4. Re: ksh : printing a file to stdout with the variables expanded

    Chris F.A. Johnson wrote:
    > On 2007-11-16, sonyantony@hotmail.com wrote:
    >>
    >> I have a file with variables like ${VAR1} ${VAR2} etc embedded in it.
    >> Is there any way I can print this file to the stdout after expanding
    >> all the variables.

    >
    > eval "printf '%s\n' \"$( < FILE )\""


    Or:

    eval "cat < $( < myfile )
    EOF"

    This interpolates the file inline into a here-document, then makes
    the shell evaluate the here document and expand the parameters in
    the process, since the 'EOF' is not quoted.

    If the file FILE contains a line that starts with "EOF", the results
    will not be pretty. But then I believe the results also won't be
    pretty if the printf version has a double quote in the input file.

    I suppose you can even fix the escaping issue, like this:

    eval "sed 's/^X//' < $( sed 's/^/X/' myfile )
    EOF"

    It's ugly, but it works.

    - Logan

  5. Re: ksh : printing a file to stdout with the variables expanded

    In article <473e9c2d$0$19738$4c368faf@roadrunner.com>,
    Logan Shaw wrote:
    >Chris F.A. Johnson wrote:
    >> On 2007-11-16, sonyantony@hotmail.com wrote:
    >>>
    >>> I have a file with variables like ${VAR1} ${VAR2} etc embedded in it.
    >>> Is there any way I can print this file to the stdout after expanding
    >>> all the variables.

    >>
    >> eval "printf '%s\n' \"$( < FILE )\""

    >
    >Or:
    >
    > eval "cat < > $( < myfile )
    > EOF"
    >
    >This interpolates the file inline into a here-document, then makes
    >the shell evaluate the here document and expand the parameters in
    >the process, since the 'EOF' is not quoted.
    >
    >If the file FILE contains a line that starts with "EOF", the results
    >will not be pretty. But then I believe the results also won't be
    >pretty if the printf version has a double quote in the input file.
    >
    >I suppose you can even fix the escaping issue, like this:
    >
    > eval "sed 's/^X//' < > $( sed 's/^/X/' myfile )
    > EOF"
    >
    >It's ugly, but it works.
    >
    > - Logan


    More simply:

    printf '0a\ncat << EOF\n.\n$a\nEOF\n.\nx\n' | ex - myfile
    source myfile


+ Reply to Thread