Reputation: 20136
I'm using virtualenv
(which sets some environment variables). Now, I want to spawn a new terminal window that have the same environment. If I try:
xterm &
I get a new terminal but the environment is the default environment, that is when I enter the following line on the new terminal:
pserve --reload development.ini
I get:
>> pserve: Command not found.
On the other hand, if I execute:
xterm -e pserve --reload development.ini &
It opens a new terminal that runs pserve. So, my questions are:
pserve
when I run it with -e
switch?Upvotes: 2
Views: 4467
Reputation: 2264
Following the advice from @dmp I added to my ~/.bashrc the following:
# save the environment, apart from readonly variables that can not be restored
alias cloneterm='set |egrep -v "^(BASHOPTS|BASH_COMPLETION_COMPAT_DIR|BASH_VERSINFO|EUID|PPID|SHELLOPTS|UID)=" > /tmp/env.tmp && $TERM &'
# restore a previously saved environment, if any
[ -f /tmp/env.tmp ] && source /tmp/env.tmp
[ -f /tmp/env.tmp ] && rm /tmp/env.tmp
Now I can simply run
$ cloneterm
and I get a new terminal window, with the same environment
Hope this helps
Notes:
Upvotes: 1
Reputation: 439
To answer your first question, a quick and dirty way of doing it is to use the sh builtin 'set' command (more see 'help set').
From the old shell:
set > ~/env.tmp
Then
xterm &
From the new shell:
. ~/env.tmp && rm ~/env.tmp
You may want to wrap this up in a script or add a couple of functions in your 'bash.rc'. You may also want to use 'mktemp(1)' or similar.
Upvotes: 4