SyntaxHighlighter JS

2013-03-02

Unix Environment Variables

  • How do I show all my environment variables?
    set

  • How do I show a specific environment variable, like PATH?
    set | grep -e "^PATH="

  • How do I set an environment variable, like ORACLE_HOME?
    export ORACLE_HOME=/usr/oracle

  • How do I delete a environment variable?
    unset ORACLE_HOME

  • How do I append to an environment variable, like appending /users/sbin to PATH?
    export PATH=${PATH}:/users/sbin

  • How do I reuse other environment variables, like adding ORACLE_HOME to PATH?
    export PATH=${PATH}:${ORACLE_HOME}

  • How do I pass environment variables to Unix shell scripts without changing my environment?
    PATH=${PATH}:/usr/local ./myShellScript.sh

  • How do I make my changes to environment variables permanent?
    Create or edit the file ~/.bashrc and add the export command to that file. For example, to make the change to ORACLE_HOME permanent, add the following line to ~/.bashrc
    export ORACLE_HOME=/usr/oracle

    After saving the file ~/.bashrc, then execute the command
    source ~/.bashrc

  • What is the difference between ~/.bash_profile and ~/.bashrc? Or setting ~/.bashrc did not make my environment variable changes permanent.
    For a detailed explanation, please read Josh Staiger's article.

    But pragmatically it doesn't matter. Just make ~/.bash_profile execute ~/.bashrc. Create or edit ~/.bash_profile and add the following line
    [ -r ~/.bashrc ] && . ~/.bashrc

No comments:

Post a Comment