understanding conditional sentence in /etc/profile
Hi,
I'd ilke to understand the meaning of the following script excerpt: Code:
for i in /etc/profile.d/*.sh ; do |
For all *.sh scripts in /etc/profile.d/
If the current shell is interactive, source(include) the sh script, otherwise source(include) the sh script but suppress output. The test for an interactive shell looks a bit complex: $- or ${-} is the current set of flags that one can turn on or off with the set command. ${-#*i} means it chops the first characters until (and including) an i from the $- The i is the flag for being interactive. If the chopping was successful the result is shorter than the $- and certainly not equal. I would have coded this more simple Code:
if [[ $- == *i* ]]; then Code:
case $- in |
/etc/profile needs to be compatible with all the shells that source it, not just bash.
|
Yes, and my case-esac sample works with all sh-style shells (but the old SySV Bourne shell).
-- It's a general disease that people think light and code heavily. The brain moves into the fingers. |
I think I'll have a lot of other questions, but first I'd like to know what flags you're referring to.
|
The tradtional option flags that you can set or unset.
For example: Code:
$ echo $- |
But these are different from the flags in this link, right? http://tldp.org/LDP/abs/html/options.html (with the exception of i and B)
Do you know any links where I can learn more of this or some other practical examples maybe? set -f means that you're usetting f? If that's so, why does it show up when you do echo $-? And the f flag is the same as in the link (no globbing)? |
The traditional option flags are the -X options in the left table column in your URL, where X are the given single letters.
They do not have an argument, that's why I call them flags. In contrast to Code:
set -o longoption Code:
set -X Code:
set -f Code:
set -o noglob |
The reason why I thought the flags in the table were different from that flags seen using echo $- was that m and h and H are missing for some reason. Why's that?:)
|
From your link:
Quote:
|
All times are GMT -5. The time now is 09:26 PM. |