i92guboj |
01-21-2011 04:03 AM |
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.
|