I am running RHEL6 (kernel 2.6.32-573.el6.x86_64).
I have aliases which are sourced upon sshing into myserver.
One of these is
alias scl-devtoolset-3='source /usr/local/bin/scls/devtoolset-3'
It is presumably aliased in non-login shells (see below), but sshing gives a login shell, and this is confirmed by the line
shopt -q login_shell && echo 'This is a login shell' || echo 'This is a non-login shell'
in my ~/.bashrc, which produces
This is a login shell
as expected. Thus, I have no idea why/where is the alias set.
How to rationalize this seemingly contradictory circumstance?
Files present in my system:
/etc/profile
/etc/bashrc
/etc/profile.d/*
~/.bashrc
Files not present in my system:
/etc/bash.bashrc
~/.profile
TL;DR
The alias appears to be set (only in non-login shells) by the following lines in /etc/bashrc:
...
if ! shopt -q login_shell ; then # We're not a login shell
...
# Only display echos from profile.d scripts if we are no login shell
# and interactive - otherwise just process them to set envvars
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
...
fi
which source file /etc/profile.d/scl-aliases.sh containing
#!/bin/bash
sources_dir=/usr/local/bin/scls
for scl in `ls $sources_dir`; do
alias scl-$scl="source $sources_dir/$scl"
done
and given that
$ ls /usr/local/bin/scls
devtoolset-3 devtoolset-4 devtoolset-6 python27 python33
This was (partially?) confirmed by executing bash -x at the command prompt after sshing.
-x). Given the cross-posting I don't think OP is shy about creating new posts thus I think the intent was not to post two distinct questions. Oh, and the first one is like two sentences long. Anyways, I'm just making a suggestion to help keep things uncluttered around here (a losing battle, I know). – B Layer Dec 02 '17 at 09:39shopt -q login_shellgives True when evaluated in ~/.bashrc, and it gives False when evaluated in/etc/bashrc, both in the same shell. That is assuming the alias is set within the citedifconstruct (otherwise, I wouldn't know where is it set). If you can reinterpret the answer in a way to answer this OP, please post the answer... I would very much welcome it! – sancho.s ReinstateMonicaCellio Dec 04 '17 at 18:23/etc/bashrcor is it/etc/bash.bashrc? If the former, would you be running macOS by any chance? – terdon Dec 04 '17 at 20:33