I am using Windows 10. I followed this tutorial on how to create bash aliases. I put the aliases in ~/.bashrc
, and used source ~/.bashrc
afterwards. When I tried to use one of the aliases, I get the following error:
$ docs
bash: docs: command not found
I opened a new PowerShell session, used bash
, tried the alias and it still gave the same error. But it only worked when I tried it on Git Bash. From what I've researched, I was opening bash in a non-interactive shell. I tried the answer on this post and put shopt -s expand_aliases
at the end of .bashrc
, but it still wouldn't work. This is what my .bashrc
looks like:
######## Aliases #######
# Git
alias gcl="git clone"
alias gco="git commit"
alias gcom="git commit -m"
alias gpus="git push"
alias gpul="git pull"
alias gbr="git branch"
alias gad="git add"
alias gre="git restore"
alias grest="git restore"
alias gsw="git switch"
alias gst="git status"
alias gcoam="git commit --amend"
alias gcoamne="git commit --amend --no-edit"
alias gcoamm="git commit --amend -m"
# Navigation
alias home="cd ~"
alias docs="cd ~/Documents"
alias labs="cd ~/Documents/VSCode"
alias open="code ."
################
shopt -s expand_aliases # allows aliases available in non-interactive shells
How do I make the bash aliases work in a non-interactive shell?
You have to turn on this feature:
shopt -s expand_aliases