LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 03: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, 04:03 AM   #2
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
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, 04:16 AM   #3
Soji Antony
Member
 
Registered: Jul 2010
Posts: 54

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


Reply



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 10:56 AM
redhat 5.2 login/profile-script ? jonaskellens Red Hat 5 08-07-2008 07:56 AM
/etc/profile script sachinh Linux - General 14 05-24-2007 11:06 PM
Script in /etc/profile.d/ won't won't work!? BlueSpirit Slackware 1 10-15-2006 11:21 AM
Is there a .profile script in Linux? rsuri Linux - Newbie 1 07-31-2003 12:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:47 AM.

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
Open Source Consulting | Domain Registration