LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-21-2011, 04:50 AM   #1
Soji Antony
Member
 
Registered: Jul 2010
Posts: 54

Rep: Reputation: 1
/etc/profile script


Quote:
This script is from /etc/profile file

Code:
for i in /etc/profile.d/*.sh ; do
    if [ -r "$i" ]; then
        if [ "$PS1" ]; then
            . $i
        else
            . $i >/dev/null 2>&1
        fi
    fi
done
Can any body tell me what the above script does ?

1. if [ "$PS1" ]; ??

When will this if condition become true ?

2. When this if condition is satisfied
* execute . $1
* else execute . $i >/dev/null 2>&1

I know $i >/dev/null 2>&1 will be executing silently .

But my question is why we need to execute $1 in two ways when that if condition is satisfied ??
 
Old 01-21-2011, 05:03 AM   #2
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
Quote:
1. if [ "$PS1" ]; ??
This is an -unreliable- way to find whether the shell is interactive or not. There are better ways, but that's out of the scope of the thread, you can read more if you are interested in the issue here:

http://www.google.com/search?ie=UTF-...nteractive+ps1

Quote:
When will this if condition become true ?
The purpose is that it will be true when the shell is interactive (i.e. when you open a terminal or login into a tty). The reality is that it will be true when PS! is set (when there's a prompt). But, you can set the prompt to an empty string on an interactive shell. Hence, this is unreliable.

Quote:
2. When this if condition is satisfied
* execute . $1
* else execute . $i >/dev/null 2>&1
The "dot" command is equivalent to the "source" command. It dumps the script into the current shell instead of running it into a new instance.

Quote:
I know $i >/dev/null 2>&1 will be executing silently .

But my question is why we need to execute $1 in two ways when that if condition is satisfied ??
The intention is to let the messages be printed when the shell is interactive, but to ignore them when the script is ran on a non-interactive shell, during init or whatever.
 
1 members found this post helpful.
Old 01-21-2011, 05:16 AM   #3
Soji Antony
Member
 
Registered: Jul 2010
Posts: 54

Original Poster
Rep: Reputation: 1
Thank you so much for your help!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] shell script /etc/profile xiaoqing87316 Programming 4 10-16-2010 11:56 AM
redhat 5.2 login/profile-script ? jonaskellens Red Hat 5 08-07-2008 08:56 AM
/etc/profile script sachinh Linux - General 14 05-25-2007 12:06 AM
Script in /etc/profile.d/ won't won't work!? BlueSpirit Slackware 1 10-15-2006 12:21 PM
Is there a .profile script in Linux? rsuri Linux - Newbie 1 07-31-2003 01:39 PM


All times are GMT -5. The time now is 08:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration