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
. "$i"
else
. "$i" >/dev/null
fi
Or
Code:
case $- in
( *i* )
. "$i"
;;
( * )
. "$i" >/dev/null
;;
esac