Command Understanding :- . $PWD/.profile

Hi,
I am new in unix, can anyone please explain the use of:

- . $PWD/.profile

Thanks,
Sujoy

Are you sure of the minus sign we see at the beginning or is it a typo?

1 Like

Please ignore the minus sign

Is this clear enough? man pages are a worthwhile reading.

. $PWD/.profile
^ ^    ^ --- dotted (= hidden) shell init file
| +--------- path in a shell variable to be expanded (current working dir)
+----------- source (= read and execute) a text file containing shell commands / constructs

this is odd as $PWD stores the actual working directory, which might be in some cases the home directory, where .profile resides, but in most not. Correct syntax is
~/.profile or $HOME/.profile
It's used to set the user environment, like variables such as PATH. It's part of a larger file set. Following pseudo code explains the sequence of execution of these files( for the popular bash shell):

Sorry to intervene here but this is not quite correct: ~/.profile is the session startup configuration. It is executed by the login process when a user logs into a system. ~/.kshrc , ~/.bashrc and similar files are shell startup configuration scripts and are executed every time a shell instance starts by the shell. As a "session" often consists only of the shell startup, the execution of some commands (which doesn't change the environment) and a logoff this difference is often blurred or doesn't matter at all. But try the following: put a line like:

PATH="$PATH:/foo"

into your ~/.bashrc and then start a nwe shell. You will see "/foo" added at the end. Now start another shell instance inside the shell - another "/foo" will be added. Start another shell inside this and again another "/foo" will be added. (The same if you put it in your ~/.kshrc and use ksh as your shell.)

Furthermore the location of the startup file for the shell can be changed. Per default it is ~/.bashrc (for bash) or ~/.kshrc (for ksh) as i said but you can control the location of the rc-script by setting the variable "$ENV". I have that usually as the last line of my ~/.profile :

export ENV=~/.kshrc

~/.bash_profile and ~/.bash_login are files which only exist in bash. I do not use them because i like all my shell sessions to be configured the same and for that i use ~/.bashrc . Also in my ~/.kshrc the PATH is always set like this:

export PATH="/bin"
       PATH="$PATH:/usr/bin"
       PATH="$PATH:/usr/local/bin"
...etc.

Notice that the first line resets the PATH completely. This way i make sure pathes are not added several times when i start new shell instances.

I hope this helps.

bakunin

1 Like