![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| script that can give login password for "ssh" without involving STDIN | gydave | Shell Programming and Scripting | 2 | 08-03-2008 07:03 PM |
| ksh script as a login shell return "no controlling terminal" | lramirev | Shell Programming and Scripting | 8 | 07-16-2008 01:31 AM |
| Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" | Lokesha | UNIX for Dummies Questions & Answers | 4 | 12-20-2007 01:52 AM |
| Reset environment - ".. /etc/.environment dev_env" | zzwu3591 | UNIX for Advanced & Expert Users | 7 | 01-12-2007 09:27 AM |
| No utpmx entry: you must exec "login" from lowest level "shell" | peterpan | UNIX for Dummies Questions & Answers | 0 | 01-18-2006 04:15 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hello fellow *nix users!
I am a bit confused how could I get an environment of a "fresh/clean" login shell, that is, the environment at that moment when user has started e.g. a new terminal/console or so. So this is the sequence of actions I should be able to do in a single shell session: 1. open a new terminal 2. source a script which will set my environment based on some rule set 3. do my tasks in that environment 4. clean the environment from exports made in step #2 5. source a new script which will do some other environment exports based on some other rule set 6. do some stuff... And this sequence goes on and on... Currently, there are two ways of doing this: a) start a new terminal each time a new environment should be taken into use b) before sourcing, start a new shell, e.g. bash/csh/what ever, and then do the sourcing... And when done -> exit that shell to get back the login shell and then start a new shell again The problem with both ways mentioned above is lazy users. They would like to source the script setting the environment and after finished with that, source a new environment setting script. So they don't want to start a new shell or open up a new terminal. So this is why I'm looking for a solution how to get an environment of a clean login shell. I don't think (might be wrong here..) there is a way to do something like: Code:
bash -clean_shell_please "env > /tmp/some_file.txt" Any ideas are highly appreciated! Thanks in advance! -Miikka |
|
||||
|
I assume you mean "clean" as in zero environment variables.
One way Code:
env - /usr/bin/ksh Code:
set | awk '{ print "unset", $1 }' > ./tmp.tmp
. ./tmp.tmp
Last edited by jim mcnamara; 10-04-2008 at 08:09 PM.. |
|
||||
|
Thanks Jim for your quick reply.
With "clean" I meant the environment user gets when he opens up a new terminal and types env. The first way you suggested + sourcing /etc/profile and ~/.profile does not result to same environment compared to new terminal session. I also get warnings "WARNING: terminal is not fully functional" after that. The second way, using awk one liner, leads to a file full of "unset $1", i.e. $1 does not get evaluated... |
|
||||
|
You can start your scripts with this sequence:
Quote:
|
|
||||
|
You are correct, however, that is how its currently done as I mentioned in my first post:
Quote:
So what I'm trying to accomplish here is some sort of way to make those environment setting scripts to reset the environment back to what it was at the time of login and then applying new settings. One thing to notice also is that I cannot force users to modify their .profile to save the environment at login time. I was hoping there would be some kind of way to use rlogin (or something else giving the same result) to get a clean login shell so that I could do the following in the beginning of each script setting an environment: * rlogin to a new shell which does not inherit the environment of parent * at rlogin shell: env > clean_env.txt * at script which is sourced: ** remove all environment variables and source clean_env.txt ** add some new environment variables on top of that I know I could do this with Java or C, but I really would like to stick with shell script/perl/awk... Sorry if I haven't been clear enough with my question ![]() |
![]() |
| Bookmarks |
| Tags |
| environment, script, scripting, shell |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|