Hello, I tried to set some user-level bash aliases, using .bashrc and storing them separately in .bash_aliases file, but it doesn’t seem to be working. There are no error messages, the shell simply doesn’t recognize the alias commands as valid. I largely looked at this Fedora Magazine article in general to guide me.
Here is how I set up my directory in ~/
.
├── .bash_history
├── .bash_history-08471.tmp
├── .bash_history-19786.tmp
├── .bashrc
├── .bashrc.d
│ └── .bash_aliases
(irrelevant files + folders excluded).
I then found a demo script for .bashrc with some arguments that I thought were useful. I pasted it into my .bashrc and edited the paths to reflect my folder structure:
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific environment
if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]; then
PATH="$HOME/.local/bin:$HOME/bin:$PATH"
fi
# Adding cargo bin path for rmpc & other compiled pckgs
export PATH="$HOME/.cargo/bin:$PATH"
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
# -----------------------------------
# Create a new permanent bash alias
# User specific aliases and functions
# @param $1 - name
# @param $2 - definition
# -----------------------------------
new-alias () {
if [ -z "$1" ]; then
echo "alias name:" && read NAME
else
NAME=$1
fi
if alias $NAME 2 > /dev/null > /dev/null; then
echo "alias $NAME existe déjà - continuer [y/n]?" && read YN
case $YN in
[Yy]* ) echo "bien compris. poursuivrons";;
[Nn]* ) return;;
* ) echo "réponse erronée." && return;;
esac
fi
if [ -z "$2" ]; then
echo "alias definition:" && read DEFINTION
else
DEFINTION="$2"
fi
if [ -f ~/.bash_aliases ]; then
echo "alias $NAME=\"$DEFINTION\"" >> ~/.bash_aliases
else
echo "alias $NAME=\"$DEFINTION\"" >> ~/.bashrc
fi
alias $NAME="$DEFINTION"
if [ -d ~/.bashrc.d ]; then
for rc in ~/.bashrc.d/*; do
if [ -f "$rc" ]; then
. "$rc"
fi
done
fi
}
unset rc
Then I verified that the shell is interactive using these instructions, and non-login using these instructions, and then executed the shell before rebooting.
~$ [ -z "$PS1" ] && echo "This shell is not interactive" || echo "This shell is interactive"
This shell is interactive
~$ echo $0
/usr/bin/bash
~$ source ~/.bashrc
Nothing happened upon multiple reboots (I just didn’t touch this for a while, had other work to do).
Finally, this is everything that I set in ~/.bashrc.d/.bash_aliases :
alias uu1='systemctl --user enable mpd && systemctl --user start mpd'
alias uu2='rmpc'
alias uu3='systemctl --user disable mpd'
alias uu4='pkill rmpc'
alias grep='grep --color=auto'
alias uefi='systemctl reboot --firmware-settings'
Could someone please take a look and let me where the issue lies? Is it in the .bashrc syntax? For example, did I place the closing bracket } in the correct place? (I wasn’t sure). Or something else?
(Please note that the command to set $PATH for cargo (Rust-compiled music app rmpc) was executed properly. I did that one a while ago. So the file overall seems to be ok.)
Thank you!