Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all! We have been experiencing an issue on site where threads have been missing the latest postings. The platform host Vanilla are working on this issue. A workaround that has been used by some is to navigate back from 1 to 10+ pages to re-sync the thread and this will then show the latest posts. Thanks, Mike.
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

setting env variable from shell script??

  • 03-04-2008 10:25am
    #1
    Registered Users, Registered Users 2 Posts: 599 ✭✭✭


    from the command line:

    setenv DISPLAY xxx

    works fine, DISPLAY variable is set to xxx. i want to be able to do this from within a shell script but get error message when i use:

    $(setenv DISPLAY xxx)

    the following line works for env in the script:

    echo $(env | grep DISPLAY)

    what's the correct syntax for $(setenv)????


Comments

  • Moderators, Arts Moderators Posts: 35,508 Mod ✭✭✭✭pickarooney


    The dollar symbol is used to denote a variable. In your echo command the $ is simply ignored and because env|grep DISPLAY is a valid command you don't get an error.
    $(setenv DISPLAY xxx) doesn't actually mean anything.

    As a script is a child process of the shell that spawns it, the script cannot set an environment variable higher up its own hierarchy. If you export the variable then it's applicable to any programs called from within the script. If you want env variables set in your script to apply once the script has finished running, you'll need to include the script in, say, .bashrc.


  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    Just for clarity:

    export DISPLAY=XXX

    will be maintained by bash after the shell script has finished.


  • Registered Users, Registered Users 2 Posts: 868 ✭✭✭brianmc


    ambasite wrote: »
    from the command line:

    setenv DISPLAY xxx

    works fine, DISPLAY variable is set to xxx. i want to be able to do this from within a shell script but get error message when i use:

    $(setenv DISPLAY xxx)

    the following line works for env in the script:

    echo $(env | grep DISPLAY)

    what's the correct syntax for $(setenv)????



    Lots of strange information in this thread.

    setenv is a C Shell command for creating an environment attribute. Is your script a C Shell script? I suspect that it's more likely that you're using the c shell (or tcsh) on the command line, but that your script is actually a Korn shell or Bash shell script.

    I don't know all of my C shell syntax off the top of my head, but in ksh and bash the $(command) syntax causes command substitution and I suspect that you're mistaken in using it at all here.

    If the script is sh, ksh or bash the syntax for creating an environment attribute (such as DISPLAY) is
    export DISPLAY=Value
    

    with no spaces on either side of the =.

    I don't agree with what Khannie says about the attribute being maintained after the script has finished though. A shell script is effectively a subshell taking it's input from a file rather than from your terminal. There is nothing that you can do in a subshell that can affect the environment of your command line shell.


Advertisement