Unix/Linux

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • how to keep the old environment setting in the new terminal

    9 answers - 377 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    Hi,
    I am using BASH on Linux. I usually issue "xterm" command to start a
    new terminal window, I find that the environment settings in the new
    window are different from the old one, it is because .bashrc is soured
    in the new window.
    I just wonder if there are some way to keep the setting same as the
    old, parent terminal?
    Thanks.
  • No.1 | | 91 bytes | |

    You answered your own question:
    Source .bashrc from .bash_profile
  • No.2 | | 943 bytes | |

    2005-09-03, linq936@hotmail.com wrote:
    Hi,
    I am using BASH on Linux. I usually issue "xterm" command to start a
    new terminal window, I find that the environment settings in the new
    window are different from the old one, it is because .bashrc is soured
    in the new window.

    I just wonder if there are some way to keep the setting same as the
    old, parent terminal?

    What environment settings?

    If they are set by the login scripts, e.g. /etc/profile,
    ~/.bashrc, ~/.bash_profile or whatever, just make sure that the
    new shell sources the same files. You may need to make your new
    shell a login shell with "xterm -ls". See the INVCATIN section
    of the bash man page for information on which files are sourced
    under what circumstances.

    If the settings you are referring to are variables set within the
    parent shell, then they must be exported before they will be seen
    by a child shell.
  • No.3 | | 975 bytes | |


    Chris F.A. Johnson wrote:
    2005-09-03, linq936@hotmail.com wrote:
    Hi,
    I am using BASH on Linux. I usually issue "xterm" command to start a
    new terminal window, I find that the environment settings in the new
    window are different from the old one, it is because .bashrc is soured
    in the new window.

    I just wonder if there are some way to keep the setting same as the
    old, parent terminal?

    What environment settings?

    If they are set by the login scripts, e.g. /etc/profile,
    ~/.bashrc, ~/.bash_profile or whatever, just make sure that the
    new shell sources the same files. You may need to make your new
    shell a login shell with "xterm -ls". See the INVCATIN section
    of the bash man page for information on which files are sourced
    under what circumstances.

    If the settings you are referring to are variables set within the
    parent shell, then they must be exported before they will be seen
    by a child shell.
  • No.4 | | 1699 bytes | |

    2005-09-05, linq936@hotmail.com wrote:

    Chris F.A. Johnson wrote:
    >2005-09-03, linq936@hotmail.com wrote:
    >Hi,
    >I am using BASH on Linux. I usually issue "xterm" command to start a
    >new terminal window, I find that the environment settings in the new
    >window are different from the old one, it is because .bashrc is soured
    >in the new window.
    >>

    >I just wonder if there are some way to keep the setting same as the
    >old, parent terminal?
    >>

    >What environment settings?
    >>

    >If they are set by the login scripts, e.g. /etc/profile,
    >~/.bashrc, ~/.bash_profile or whatever, just make sure that the
    >new shell sources the same files. You may need to make your new
    >shell a login shell with "xterm -ls". See the INVCATIN section
    >of the bash man page for information on which files are sourced
    >under what circumstances.
    >>

    >If the settings you are referring to are variables set within the
    >parent shell, then they must be exported before they will be seen
    >by a child shell.
    >

    Sorry, let me explain:
    in the parent shell, I re-defined $PATH and also defined some user
    variables, and I did "export" them.

    The problem is most of such viables are initially defined in .bashrc
    together with $PATH, so when I spawn a new terminal, "xterm &", they
    get reset.

    What I want is, somehow, i can get a new terminal that has the exact
    identical env settings as the parent.

    xterm -e bash
  • No.5 | | 1731 bytes | |


    Chris F.A. Johnson wrote:
    2005-09-05, linq936@hotmail.com wrote:

    Chris F.A. Johnson wrote:
    >2005-09-03, linq936@hotmail.com wrote:
    >Hi,
    >I am using BASH on Linux. I usually issue "xterm" command to start a
    >new terminal window, I find that the environment settings in the new
    >window are different from the old one, it is because .bashrc is soured
    >in the new window.
    >>

    >I just wonder if there are some way to keep the setting same as the
    >old, parent terminal?
    >>

    >What environment settings?
    >>

    >If they are set by the login scripts, e.g. /etc/profile,
    >~/.bashrc, ~/.bash_profile or whatever, just make sure that the
    >new shell sources the same files. You may need to make your new
    >shell a login shell with "xterm -ls". See the INVCATIN section
    >of the bash man page for information on which files are sourced
    >under what circumstances.
    >>

    >If the settings you are referring to are variables set within the
    >parent shell, then they must be exported before they will be seen
    >by a child shell.
    >

    Sorry, let me explain:
    in the parent shell, I re-defined $PATH and also defined some user
    variables, and I did "export" them.

    The problem is most of such viables are initially defined in .bashrc
    together with $PATH, so when I spawn a new terminal, "xterm &", they
    get reset.

    What I want is, somehow, i can get a new terminal that has the exact
    identical env settings as the parent.

    xterm -e bash
  • No.6 | | 653 bytes | |

    6 Sep 2005 14:06:52 -0700, linq936@hotmail.com
    <linq936@hotmail.comwrote:
    , Thanks, it works somewhat,, and I find a new problem which I had
    not imaged.

    In .bashrc, I source some scripts, such as define some functions. In
    parent terminal, I use them usually. In child terminal which was
    created from the above command, those functions and aliases are
    un-defined.

    Maybe I am asking something crazy, without source those scripts
    specifically, can I get an "identical" new terminal which operates
    exactly same as the parant?

    screen -xR
    (For this to work, screen must be running on the original terminal.)
  • No.7 | | 983 bytes | |


    Bill Marcum wrote:
    6 Sep 2005 14:06:52 -0700, linq936@hotmail.com
    <linq936@hotmail.comwrote:
    , Thanks, it works somewhat,, and I find a new problem which I had
    not imaged.

    In .bashrc, I source some scripts, such as define some functions. In
    parent terminal, I use them usually. In child terminal which was
    created from the above command, those functions and aliases are
    un-defined.

    Maybe I am asking something crazy, without source those scripts
    specifically, can I get an "identical" new terminal which operates
    exactly same as the parant?

    screen -xR
    (For this to work, screen must be running on the original terminal.)
    --
    I tried, it does not work for me. Here is what I did,

    [ in parent shell]
    source a_script

    which a_command
    [a_command is found]

    screen -xR

    Ctrl-A C
    [a new window is created]

    which a_command
    [a_command is not found]

    Any idea?

  • No.8 | | 680 bytes | |

    linq936@hotmail.com wrote:
    In .bashrc, I source some scripts, such as define some functions. In
    parent terminal, I use them usually. In child terminal which was
    created from the above command, those functions and aliases are
    un-defined.

    Quick'n'dirty approach: use export -f to mark the functions exported.

    More systematic approach: organize your .bash_profile and .bashrc to
    separate things that provide initial defaults for variables and things
    you want done in every shell. You can also make parts of these file
    conditional on whether they are running in a login shell or not, an
    interactive shell or not, etc.

  • No.9 | | 875 bytes | |

    Sat, 03 Sep 2005 04:47:23 +0200, <linq936@hotmail.comwrote:

    Hi,
    I am using BASH on Linux. I usually issue "xterm" command to start a
    new terminal window, I find that the environment settings in the new
    window are different from the old one, it is because .bashrc is soured
    in the new window.

    I just wonder if there are some way to keep the setting same as the
    old, parent terminal?

    I gues you could experiment with something along the lines:

    set >/tmp/set.$$
    echo "rm -f /tmp/set.$$" >>/tmp/set.$$
    xterm -e bash /tmp/set.$$ &

    The idea here is to save the state of your current xterm session in a
    file, and then direct the bash in the new window to read this file
    instead to ~/.bashrc. Notice that as soon as the new shell has read
    the file, it deletes it.

    Regards,
    Enrique

Re: how to keep the old environment setting in the new terminal


max 4000 letters.
Your nickname that display:
In order to stop the spam: 9 + 8 =
QUESTION ON "Unix/Linux"

EMSDN.COM