Usenet comp.unix.tru64 (2000-2013)
 help / color / mirror / Atom feed
From: Bob Harris <nospam.News.Bob@remove.Smith-Harris.us>
Subject: Re: some queris on .profile file
Date: Mon, 19 Jun 2006 00:57:36 GMT	[thread overview]
Message-ID: <nospam.News.Bob-42694A.20580918062006@news.verizon.net> (raw)
In-Reply-To: 1150665868.779077.294420@y41g2000cwy.googlegroups.com

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 9645 bytes --]

In article 
<1150665868.779077.294420@y41g2000cwy.googlegroups.com>,
 "mehaboob@gmail.com" <mehaboob@gmail.com> wrote:

> Bob Harris wrote:
> 
> > In article <1150644822.914802.41470@r2g2000cwb.googlegroups.com>,
> >  "mehaboob@gmail.com" <mehaboob@gmail.com> wrote:
> >
> > > Bob Harris wrote:
> > >
> > > > In article
> > > > <1150576687.026459.179060@u72g2000cwu.googlegroups.com>,
> > > >  "mehaboob@gmail.com" <mehaboob@gmail.com> wrote:
> > > >
> > > > > Piotr Hosowicz wrote:
> > > > >
> > > > > > mehaboob@gmail.com wrote:
> > > > > >
> > > > > > > I did understand about your explanation for ./.profile
> > > > > > > But what is the initail dot and space for?
> > > > > > > i.e    . ./.profile
> > > > > >
> > > > > > Hi Mehaboob,
> > > > > >
> > > > > > In some shells there is a command named source, if you do :
> > > > > >
> > > > > > source some-script.sh
> > > > > >
> > > > > > ... then some-script.sh is sourced into current running shell, 
> > > > > > meaning
> > > > > > "including" the script some-script.sh. There are some gotchas, like 
> > > > > > for
> > > > > > example if you have :
> > > > > >
> > > > > > exit
> > > > > >
> > > > > > .. in some-script.sh then it will exit the whole calling shell and 
> > > > > > not
> > > > > > terminate "sourceing" some-script.sh.
> > > > > >
> > > > > > Single dot is equivalent to source'ing some script, so above is
> > > > > > equivalent to :
> > > > > >
> > > > > > . some-script.sh
> > > > > >
> > > > > >
> > > > > > --
> > > > > > No signature found.
> > > > >
> > > > > Thanks for taking time to explain.
> > > > > I have some more confusion
> > > > >
> > > > >
> > > > > if we apply the  rules source some-script.sh then we get
> > > > > source <filename>  i.e
> > > > > source .profile
> > > > >
> > > > > If I have execute .profile then the command would be
> > > > > ./<filename>  i.e
> > > > > ./.profile
> > > > >
> > > > > But my confusion why do we have source and execute
> > > > > source execute the file  i.e
> > > > > souce ./<filename>    i.e
> > > > > . ./.profile
> > > > >
> > > > >
> > > > > Regards,
> > > > > Mehaboob
> > > >
> > > > Sourcing a script (eg:  . ./.profile) will allow tht script to set
> > > > local variables, environment variables, shell options, aliases,
> > > > create functions, etc... for your running shell.  In this case it
> > > > would be your interactive shell.  So it can alter your current
> > > > shell environment.
> > > >
> > > > Invoking an executable shell (eg:  ./.profile) will run that shell
> > > > script in a subprocess.  All variables, environment variables,
> > > > shell options, aliases, and functions created or modified will be
> > > > lost as soon as that script finishes.
> > > >
> > > > Think of it as going to dinner with a friend, and your buying.
> > > > You both consuem food, but when your friend leaves, the calories
> > > > he/she consumed, leaves with them.  But the calories you ate get
> > > > to go home with your.  Bon App�tit :-)
> > > >
> > > >                                         Bob Harris
> > >
> > >
> > > Hi,
> > >
> > > Thanks for the explanation.Now this brings up some queries in my
> > > mind....
> > >
> > > 1)What are environment variables?...Are these the only variables that
> > > are set in .profile file?
> >
> > You should really REALLY think about going out to your local book
> > store, get something to drink in the cafe, and browse some of the
> > UNIX for MacOSX users books, or even a few of the Linux or UNIX
> > shell related books.  Just page through the first few chapters and
> > they should give you a feel for some of the shell basics.
> >
> > Environment variables are values that get passed to subprocesses
> > that are created.  For example, your PATH is an environment
> > variable, and it is a colon separated list of directories where
> > all the executable programs you want to be able to run by just
> > typing the file name are to be found.  The order of the
> > directories is the order that they are searched.  If there are
> > duplicate scripts or executables, the first one found is used.
> >
> > So using PATH as an environment variable example, you can set PATH
> > to include additional directories, and then when you run scripts,
> > they can find your commands as well as the other commands
> > available via PATH.
> >
> > Environment variables are only passed down.  Changes made to an
> > environment variable in a subprocess is never returned to the
> > parent process.
> >
> > Environment variables are set in bourne shell, korn shell, bash,
> > zsh, POSIX shell, or other shells derived from the bourne shell
> > using
> >
> >     variable name='value'
> >     export variable name
> > or
> >     export variable name='value'
> >
> > The C shell and tcsh environment variables are set using:
> >
> >     setenv variable name 'value'
> >
> > .profile (used by bourne shell derived shells) is the general
> > place to set environment variables that you want to always have
> > when you login.  They can be set other ways, especially if you
> > have a script or program that needs additional or different values
> > from what is established during your login.  Generally the scripts
> > or programs would make their own modifications as needed.  There
> > are a few other ways to actually set environment variables, but I
> > think we can skip them for now, as they are less interesting to
> > your needs.  A good book on the shell you are using would cover
> > this if by some remote possibility you would really need this.
> >
> > In addition to .profile, there is generally a /etc/profile that is
> > invoked for every bourn shell that logs in.  A global for all
> > users that use bourne shells.
> >
> > If you are a csh or tcsh user, then there are similar but
> > differently named initialization files .login, .cshrc, .tcshrc,
> > /etc/csh.login, /etc/csh.cshrc
> >
> > And some environment variables are created by the shell itself
> > when it starts up.
> >
> > And it is possible that the process the accepts your username and
> > password, and starts up your shell, may pass along some
> > environment variables.
> >
> > Local shell variables may be set in .profile.  These would be used
> > by the shell itself.  For example HISTSIZE, MAILCHECK, IGNOREEOF,
> > etc... are local shell variables that control the behavior of your
> > interactive shell.  The man page for your shell should be able to
> > list a lot of the variables that may be of interest.
> >
> > Since most bourne shells can have local functions, you can have
> > local variables that either maintain state or control their
> > behavior.  Since these are user created local functions, what
> > variables and what they do is up to you the creator of those local
> > functions.
> >
> > You asked a simple question, and you get an hour long class :-)
> >
> >
> > > 2)Are the environment available for all the script intiated from the
> > > shell?
> >
> > Yes.  Environment variables are passed down the parent/child
> > chain.
> >
> > But again, they only go down.  Modifications to environment
> > variables in a child only get passed to their children, never back
> > to their parents.
> >
> > > 3)Is it possible that the .profile does not get sourced when I login ?
> >
> > Unlikely.  Too many UNIX users in the world depend on this.
> >
> > However, if your shell is really bash, then it first looks for
> > .bash profile, then .bash login, then .profile.  First one found
> > it executed.  The remainder are ignored, unless you have commands
> > in the one that does get executed to source the others.
> >
> > > 4)When I run the command env,variables listed...Are these the variables
> > > that are set using .profile ,if not where are these variables being
> > > set?
> >
> > As stated above, they could be set by the process that creates
> > your login shell (the one that logs you in), they could be set by
> > /etc/profile, and the shell itself might create a few.
> >
> > You can remove an environment variable using unset
> >
> >     unset some env var
> >
> > But be careful that you do not mess things up for yourself.
> > Screwing up PATH can be a pain.  Not fatal, but very annoying.
> >
> > > Mehaboob
> >
> > Again, it is time to visit the bookstore.  Browse some UNIX for
> > MacOSX books.  Browse some UNIX and Linux books on shells (bash is
> > the default shell on MacOSX).  After drinking several cafe drinks
> > you find one you like and want to read more, buy it.  Otherwise
> > keep buying cafe drinks (bookstore has to make money some how :-) )
> >
> >                                         Bob Harris
> 
> Thanks a million for such an amazing explanation.
> 
> I am an experienced unix user...but nowardays i have this quest to
> understand anything and everthing related to unix...somehow i fantasise
> about being some unix geek.
> 
> My quest has just started and I hope I dont take much time to master
> it!
> 
> Any comments and suggestions welcome!
> 
> Mehaboob

Then for your quest, I highly recommend "The UNIX Programming 
Environment" by Kernighan and Pike.  It is copyright 1984 (I 
think), but I still think it is one of the best books for 
explaining the command line, beginning shell scripts, pipes, 
etc...  You do not need to read all of it, as it goes into C 
programming more, but the first 5 or 6 chapters are great for most 
UNIX users that want to get into scripting.  It will provide a lot 
of the foundation.  Just keep in mind that UNIX and friends have 
more forward a lot since 1984, so there are more features in 
shells, and utilities.

Good luck.

                                        Bob Harris


      reply	other threads:[~2006-06-19  0:57 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-15 10:15 some queris on .profile file mehaboob
2006-06-15 12:37 ` Wim Cossement
2006-06-15 19:55 ` Adam Price
2006-06-16  9:15   ` mehaboob
2006-06-16 15:27     ` Wim Cossement
2006-06-17 18:21       ` mehaboob
2006-06-17 18:56         ` Piotr Hosowicz
2006-06-17 20:38           ` mehaboob
2006-06-17 22:07             ` Piotr Hosowicz
2006-06-18  1:21             ` Bob Harris
2006-06-18 15:33               ` mehaboob
2006-06-18 17:57                 ` Bob Harris
2006-06-18 21:24                   ` mehaboob
2006-06-19  0:57                     ` Bob Harris [this message]
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox