1

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.

  • 1
    In addition there is another post from OP here https://unix.stackexchange.com/questions/408095/trace-sequence-of-scripts-commands-executed-upon-ssh ...it is directly related to this one...it should not be separate IMO – B Layer Dec 01 '17 at 04:07
  • 1
    @BLayer I don't see why the two are related. Yes, the second might be a useful tool for this one, but it is a separate question and can (and should) stand on its own. – terdon Dec 01 '17 at 14:42
  • @terdon Surely you see how they are related. OP posted that question while working on the problem then less than an hour later posted this question (presumably after getting more information by using -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:39
  • OP here... Just a few comments. 1) Yes, this is cross-posted. I am not sure this is "bad practice", given that the two sites seem to be a perfect fit for the question, and that is why I cross-posted. I wouldn't see strong arguments against it. And if so, they would perhaps also touch upon the existence of the two sites. 2) I am not "shy" about creating new posts, whenever I think them useful for the community and myself. I usually do reasonable to significant research prior to posting, probably well above average (without being infallible)... TBC – sancho.s ReinstateMonicaCellio Dec 04 '17 at 03:42
  • 1
    ... Cont. 3) The two questions came from a single work session, but I still consider them two different questions, with their own separate meaning, coinciding 100% with @terdon. – sancho.s ReinstateMonicaCellio Dec 04 '17 at 03:45
  • The first one is not "like" two sentences long... it is two sentences long. Would this make it less worth @BLayer? In the end, I see little focus on the question itself...
  • – sancho.s ReinstateMonicaCellio Dec 04 '17 at 03:47
  • This is a huge discussion that has been had many times over on the main meta and ours, let's not repeat it in the comments. By the way, have you answered your question? If so, please post it as an answer. If not, I think the missing piece you're looking for is explained in this excellent answer. – terdon Dec 04 '17 at 14:14
  • @terdon - I agree in that the answer you linked is quite comprehensive. But I did not find it answers this question. It would not explain why the test shopt -q login_shell gives 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 cited if construct (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
  • Ah, I only now understood what is confusing you. Could you edit and clarify a bit? I mean state explicitly that your question is why is this alias set in login shells. Also, what OS is this? Is it Ubuntu (since you'd posted there)? And do you really mean /etc/bashrc or is it /etc/bash.bashrc? If the former, would you be running macOS by any chance? – terdon Dec 04 '17 at 20:33
  • @terdon - Updated question, and added answer. – sancho.s ReinstateMonicaCellio Dec 05 '17 at 00:35