Score:1

alias settings nor working at logon

at flag

Newly installed hirsute = 21.04. Installed out of the package, created my own personal account, the default .bashrc is present in my homedir and to make sure there is a .bash_aliases too. Both mention alias ll='ls -alF' still this alias is not available after logon. Is this a bug or am I missing something?

NAME="Ubuntu"
VERSION="21.04 (Hirsute Hippo)"

karel@schal:~$ pwd ; ls -al .bash*
/home/karel
-rwxr-xr-x 1 karel users   53 Sep 26 06:22 .bash_aliases
-rw------- 1 karel users 9834 Sep 26 06:23 .bash_history
-rw-r--r-- 1 karel users 3771 Aug 31 23:17 .bashrc
karel@schal:~$ cat .bash_aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
karel@schal:~$ ll
ll: command not found

edited after a not-very-friendly comment, to add:

karel@wiske:~$ ssh [email protected]
[email protected]'s password: 
Welcome to Ubuntu 21.04 (GNU/Linux 5.11.0-34-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

0 updates can be applied immediately.


The list of available updates is more than a week old.
To check for new updates run: sudo apt update
Last login: Sun Sep 26 09:37:21 2021
karel@schal:~$ alias
karel@schal:~$ /bin/bash
karel@schal:~$ alias
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'

and that behaviour is identical, whether logging in per ssh or in the local graphical environment or on a local text-only console (dev/tty5 and similar)

Also, as requested, excerpt from ~/.bashrc:

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

[further edited as requested]

karel@schal:~$ ls -al ~/.bash_profile  ~/.bash_login ./.profile
ls: cannot access '/home/karel/.bash_profile': No such file or directory
ls: cannot access '/home/karel/.bash_login': No such file or directory
ls: cannot access './.profile': No such file or directory
karel@schal:~$ ps -p $$ | tail -n1 | awk '{print $NF}'
bash
vn flag
You need to [include/source it from your `.bashrc`](https://askubuntu.com/a/5278/349837). Run `alias` to list all your available aliases
Karel Adams avatar
at flag
Thank you, Pablo. But that had been checked, and is only normal for the "vanilla" default installation. As for the "alias" command, it returns zero output.
sudodus avatar
jp flag
Does it work [temporarily] to add an alias directly on the command line, for example `alias rm='rm -i'` ? Does it work [persistently] to add an alias into `~/.bashrc`, the next time you open a terminal window or text screen with `bash`?
Karel Adams avatar
at flag
Adding an alias from the command line works, yes. But whatever I tweak to .bashrc or .bash_aliases has zero effect. I am beginning to doubt whether .bashrc gets executed at all. Checked /var/log/syslog but found nothing relevant.
sudodus avatar
jp flag
It seems you are you running some other shell program? What happens, if you start `bash` explicitly with the command line `bash` ?
sudodus avatar
jp flag
Did you tweak any of the commands or configuration files, that might stop executing `~/.bashrc` ? Or is it possible that someone else tweaked the system to make that happen?
terdon avatar
cn flag
Please [edit] your questions and i) tell us what happens if you add an alias definition to your `~/.bashrc` and _not_ the non-standard `~/.bash_aliases`. Does that work? ii) show us the output of `echo $SHELL` and `ps aux -p $$` so we can see what shell you are running. iii) Clarify how you log in. Is this a local system or a remote one? Do you log in via the GUI or perhaps by ssh? Finally, don't tell us "it has been checked". Show us the actual line from your `~/.bashrc` that reads the `~/.bash_aliases` file since that is not a bash feature, and is an Ubuntu modification.
vanadium avatar
cn flag
Something will be wrong earlier in your `.bashrc`. Check by moving it out (renaming it) then copying in the system default .bashrc (which indeed is set up to source .bash_aliases): cp /etc/skel/.bashrc .
sudodus avatar
jp flag
It is also possible that you are not running bash but some other shell by default, for example csh, tcsh, zsh. Please check according to the commands in terdon's comment.
Karel Adams avatar
at flag
@vanadium: I looked into that, but to no avail. ```diff .\.bashrc /etc/skel/.bashrc``` yielded zero output.
terdon avatar
cn flag
I assume you mean my comment when you say "a not-very-friendly comment". If so, sorry! I didn't mean to come across as brusque. If that's how it came across, I must have expressed myself badly. My apologies. For what it's worth, I had also upvoted your question since yesterday.
Score:3
cn flag

When logging in over ssh, you are running what is known as an interactive login shell, and not an interactive non-login shell which is what happens when you open a terminal once logged in. Login shells do not read ~/.bashrc and instead read ~/.profile, ~/.bash_profile and ~/.bash_login. This is why your aliases are not present. For more details on this and the differences between the initialization files of various shell types, see Why are scripts in /etc/profile.d/ being ignored (system-wide bash aliases)?. This is also why you do get your aliases when you run /bin/bash since that starts a non-login shell and will read ~/.bashrc.

That said, Ubuntu's default ~/.profile file includes these lines:

# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi

So it should actually be reading your ~/.bashrc as well. If this isn't happening, I suspect one of the following:

  1. You (or someone) have created a ~/.bash_profile file. That would cause the ~/.profile file to be ignored. As explained in man bash (emphasis mine):

    When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes com‐ mands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

    So if either ~/.bash_profile or ~/.bash_login exist, then anything in ~/.profile is ignored.

  2. You (or someone else) have created your own ~/.profile which does not source ~/.bashrc.

  3. You are not actually running bash. You can check this by running ps -p $$ | tail -n1 | awk '{print $NF}' in the shell where you don't have aliases. If the output isn't bash, you are running a different shell. Perhaps you've set your default login shell to sh, which is dash on Ubuntu. You can check the current value with echo $SHELL and you can change it with chsh.


Based on your latest edit, it seems that your case is:

  1. You don't have a ~/.profile for some reason. And, based on your last edit, this seems to be the case. So just copy the default .profile from /etc/skel and you should be fine next time you log in:

    cp /etc/skel/.profile ~/
    
Score:1
at flag

@terdon had it right: for some reason or other, there was no .profile in my homedir. All was okay after - as suggested - cp /etc/skel/.profile ~

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.