• Post Reply Bookmark Topic Watch Topic
  • New Topic

Linux newbies - Running scripts in linux  RSS feed

 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cant believe this...
I think I would have spent two hours trying to get my bash shell to load up environment settings from a script. Like the way you run autoexec.bat in windows. The script will run ok, but none of the environment settings changes I was making were getting saved.
Turns out you need to put a . before you invoke the script, so that bash wont start a new sub-process to run the script, which when exits and dies also takes the changes you made with it.
so now I run my script as
bash> . ./setup_env
and it works.
Linux is fun, isnt it?
Anyone else had any interesting experience when starting out with Linux!
ps. What would we do without internet - http://www.ale.org/archive/ale/ale-1999-11/msg00084.html
[ February 03, 2004: Message edited by: Sonny Gill ]
 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, if you make your script executable (chmod +x setup_env), then you can do ./setup_env.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Adrian Yan:
Actually, if you make your script executable (chmod +x setup_env), then you can do ./setup_env.

Yes, you can; but then, as the original poster reports, the script runs in its own process, and any environment settings effect only the subshell, not the command line you're sitting at.
 
Ajeet Jose
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
add that . in the Path then you can call the scripts just by entering its name without the . in front.
export PATH=$PATH:.
To keep the env settings to all threads (shells and sub shells) launched, edit .bashrc or .bash_profile.
eg. edit .bashrc file to add JAVA_HOME
export JAVA_HOME=/usr/tools/java
[ February 05, 2004: Message edited by: Ajeet Jose ]
 
Tim Holloway
Saloon Keeper
Posts: 18800
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or, in other words, in Unix, the environment is distinct for each shell instance (e.g. executing script). Which is actually sensible considering you can use the "&" feature to spin off ansynchronously-executing processes that might blow up in mid-execution if you changed the environment they were depending on.
So in Unix, you have to explicitly publish changes to the outer environment. Otherwise you're just changing a clone of that environment that will be destroyed when your script executes.
Assuming you aren't using arcane shell options, anyway!
 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ajeet Jose:
add that . in the Path then you can call the scripts just by entering edit .bashrc or .bash_profile.

Well actually I dont mind typing that . in front too much, kinda find it cute
you see my problem was that because of some configuration mistake or something it wont recognize my NIS login, so I cant login through the graphical login manager. But I can login as root and then su to the username. I tried a few things, but nothing worked. Finally, I just changed /etc/inittab to make the default login from command line. I log in as root, su to my username, and then start the x-server. So, I need to run a script to load up my .bash_profile commands.
Anybody run into this problem!! I can finger my username, and ypwhich identifies the NIS server.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!