Professional Web Applications Themes

How do I bring in ENV - UNIX Programming

How do I bring in environment variables into a shell? In a csh I can do a source my_file Here's an example file -> init #!/usr/bin/sh set -x; TOOLBOX=some_path; export TOOLBOX; file -> go #!/usr/bin/sh set -x printf "This is sh\n"; eval init gs40; echo "TOOLBOX : '$TOOLBOX'"; exec "perl"<<DO_PERL use Data::Dumper; _ = qw ( This is perl ); print Dumper(\_); print "TOOLBOX = '$ENV{TOOLBOX}'\n"; DO_PERL; printf "This is sh again\n"; echo "TOOLBOX : '$TOOLBOX'" WHere the eval init it will eval the file but the TOOLBOX variable does not exists. I've tried exec init but the script stops ...

  1. #1

    Default How do I bring in ENV

    How do I bring in environment variables into a shell?

    In a csh I can do a source my_file

    Here's an example
    file -> init
    #!/usr/bin/sh
    set -x;
    TOOLBOX=some_path;
    export TOOLBOX;

    file -> go
    #!/usr/bin/sh
    set -x
    printf "This is sh\n";

    eval init gs40;

    echo "TOOLBOX : '$TOOLBOX'";

    exec "perl"<<DO_PERL

    use Data::Dumper;

    _ = qw ( This is perl );

    print Dumper(\_);
    print "TOOLBOX = '$ENV{TOOLBOX}'\n";

    DO_PERL;

    printf "This is sh again\n";
    echo "TOOLBOX : '$TOOLBOX'"





    WHere the eval init it will eval the file but the TOOLBOX variable does
    not exists.

    I've tried exec init but the script stops after the exec.

    How can I get the variables exported int he init script into the current
    environment?


    here is from the man page
    sh
    The exec command specified by the arguments is executed in
    place of this shell without creating a new process.
    Input/output arguments may appear and, if no other arguments
    are given, cause the shell input/output to be modified.

    The arguments to the eval built-in are read as input to the
    shell and the resulting command(s) executed.

    --
    ___ _ ____ ___ __ __
    / _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
    / _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
    /____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
    /___/
    Texas Instruments ASIC Circuit Design Methodlogy Group
    Dallas, Texas, 214-480-4455, com

    Billy Guest

  2. #2

    Default Re: How do I bring in ENV

    fu-berlin.de wrote: 
    >

    >

    >
    >
    > export TOOLBOX=some_path
    >
    > will also do.[/ref]

    Only in Bash. On most Unices, only the long form is correct. On Linux,
    of course, "sh" is really bash, so both forms work.

    Jeff Guest

  3. #3

    Default Re: How do I bring in ENV

    Billy N. Patton <com> wrote: 
     
     

    export TOOLBOX=some_path

    will also do.
     

    Of course, because the shell gets _replaced_ by the script (running in its
    own shell) and when it's done you don't get back into the old shell (which
    does not exist anymore).
     

    You do the same in (ba)sh as in csh, you just source the 'init' script
    instead of running it by

    # . init

    or, in the long version

    # source init
    Regards, Jens
    --
    \ Jens Thoms Toerring ___ fu-berlin.de
    \__________________________ http://www.physik.fu-berlin.de/~toerring
    Jens.Toerring@physik.fu-berlin.de Guest

  4. #4

    Default Re: How do I bring in ENV

    Jeff Schwab <net> wrote: [/ref]
     

    Thanks, I probably should try to get a "real" sh, the above works the
    bash way even if it's invoked as sh (which I did assume to make bash
    more sh-like but which mostly seems to just change the start-up
    behaviour as I found out after I now took a closer look).

    Regards, Jens
    --
    \ Jens Thoms Toerring ___ fu-berlin.de
    \__________________________ http://www.physik.fu-berlin.de/~toerring
    Jens.Toerring@physik.fu-berlin.de Guest

  5. #5

    Default Re: How do I bring in ENV



    Billy N. Patton wrote: 

    In many shells, anything enclosed in single quotes is immune to
    variable substitution.

    --

    Fletcher Glenn

    Fletcher Guest

  6. #6

    Default Re: How do I bring in ENV

    On 13 Feb 2004 08:31:11 GMT, "Chris F.A. Johnson"
    <com> wrote:
     [/ref]
    >[snip] 
    >>
    >> This is simply not true. POSIX specifies both forms, and IIRC
    >> correctly, in early Bourne shells, it was the LONG form that couldn't
    >> be used.[/ref]
    >
    > Which are you calling the LONG form?[/ref]

    GOod popint -- I may have completely misunderstood
    the previous poster!

    By Long, I was thinking of

    expot NAME=VALUE

    Of course it's clear to me (now) that someone could easily
    understand the long form to refer to the other syntax.
     

    Agreed. And sorry for the confusion.

    Cheers,

    Michael
    Michael Guest

  7. #7

    Default Re: How do I bring in ENV

    On Thu, 12 Feb 2004 06:49:12 -0600, Billy N. Patton
    <com> wrote: 
    Naming a program "init" is almost as bad as "test", except that "init"
    will probably only cause trouble if you are root.


    --
    Incrsease your earoning poswer and gaerner profwessional resspect.
    Get the Un1iversity Dewgree you have already earned.
    [from the prestigious, non-accredited University of Spam!]
    Bill Guest

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139