Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is it possible to invoke a bash such that everything about my environment (aliases, function, exported/non-exported variables, etc) will be present in the new shell?

I'd settle for just getting the shell variables that aren't part of my environment. I run bash --norc and the first thing I notice is I've lost $PS1 and my ls colours. I could simply export those variables before calling bash, but I'm worried about the whole slew of other things I might miss.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

You might want to look into the alias and set command. If run without parameters, alias will list all defined parameters and set will list all variables and functions. Pushing the output of these commands to a temporary file and then telling bash to read this file as an rc file may accomplish what your looking for.

share|improve this answer
    
This is the closest I've been yet, but I've finally accepted that what I really want is impossible. I want to write a Perl script that sets my environment. It would do some stuff, set some variables, and finally exec bash. I can't afford to let the environment be tainted by rc init files, but I want things like ls coloring and a descent PS1. I think maybe my best bet is to have the Perl script print the environment changes, and have the user invoke it with back ticks. –  Andrew Wood Jan 27 '11 at 15:55
    
depending on the complexity of the perl script, have it write it's own temporary rc file and then invoke bash with: bash --rcfile <path-to-the-temp-rc-file> This will not load the system wide or user rc file, only the file specified. –  karategeek6 Jan 27 '11 at 16:17
    
I was part way through doing exactly that when I realized the script won't have access to its parent's aliases and function - only its environment. –  Andrew Wood Jan 27 '11 at 16:20
add comment

No.

You can, however, enable auto-export of functions and variables by adding set -a at the top of your rc script.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.