ZSH not recognizing my aliases?

BashShellShZshZshrc

Bash Problem Overview


Using iTerm2 with zsh and it isn't recognizing my aliases. Sometimes I have to work in an IDE and can't just easily vim something and the stupid people thought it a good idea to name their applications like MyReallyLongApplicationName.app and since .html files open by default in browsers, I have to:

open -a MyReallyLongApplicationName.app something.html

I have an alias in my .zshrc like:

alias ide="open -a MyReallyLongApplicationName.app"

But zsh won't recognize my aliases. I tried another one just to see if it was me but none of the aliases I create are recognized. Just get "zsh: command not found: ide" or whatever.

So I'm not sure what I'm doing wrong and I've been searching around all day trying to fix things in zsh and the like. As a note, I'm not a pro at Linux/Unix systems so if you're too technical and vague I probably won't understand what you're telling me.

Thanks!

Bash Solutions


Solution 1 - Bash

if you do a very simple alias in zsh, does it work? open your .zshrc file, and add the following line:

alias ls='ls -GpF'

after adding that line, type this line in your Terminal:

source ~/.zshrc

tell us what happens. Also, just for shiggles, make sure you are using single quotes vs. double quotes, I have seen that make a difference in the past on different versions of shells/OS/whatnot.

Solution 2 - Bash

Add "source ~/.bash_profile" to your ~/.zsh config file.

Solution 3 - Bash

Put this line:

/source: 'source ~/.bash_profile' into ~/.zshrc 

Solution 4 - Bash

After saving changes in ~/.zshrc file, open a new shell window and execute the command in it.

Solution 5 - Bash

Sometimes the simple solution is what we need... Add "source ~/.bash_profile" to your ~/.zshrc config file

echo source ~/.bash_profile >>  ~/.zshrc

Solution 6 - Bash

I needed to manually add the alias to my zsh config file and then run the source command on it.

echo alias this='some command' >> ~/.zshrc
source ~/.zshrc

Solution 7 - Bash

Make sure the double quotes are actual double quotes and not some other character which looks like double quotes.

I was editing ~/.zsh-aliases in OSX - TextEdit, which, when hitting the double quotes key substituted it for another special double quotes character, which is not what ZSH expects.

After editing the alias file with Sublime and replacing the old double quotes with actual double quotes everything runs just fine.

Hope this helps.

Solution 8 - Bash

I had all my aliases on ~/.bash_profile, so i added at the last line on ~/.zshrc the following line: . ~/.bash_profile and it worked for me.

Solution 9 - Bash

You should put alias at the end of ~/.zshrc file. you can use below command to do that:

echo alias this='some command' >> ~/.zshrc

after that run

source ~/.zshrc

then, open a new terminal and execute the command in it.

Solution 10 - Bash

In my case issue was space b/w aliasName and equalTo. you should have to remove those space.

bad assignment

alias keu = 'k exec -it utils bash' 

correct one

alias keu='k exec -it utils bash'

Solution 11 - Bash

I'm using both bash and zsh with one .bashrc, .bash_aliases and .zshrc file.

Put this in you .zshrc to load bash files:

# shortcut to refresh .zshrc
alias refz="source ~/.zshrc"

# Load bash files to zsh
test -f $HOME/.bashrc && . $HOME/.bashrc
test -f $HOME/.bash_aliases && . $HOME/.bash_aliases

If you have many bash aliases and functions you may will have some error messages like:

/proc/self/fd/13:12310: bad option: -t

caused by bash specific lines in.bash_aliases or .bashrc files

You can skip those problematic ones using:

if [ -n "$BASH" ] ;then
    lines to ignore by zsh
fi

For example kubectl autocompletion

# To fix error massage .bashrc:16: command not found: shopt
# Check if bash is the current shell, if not, skip it
if [ -n "$BASH" ] ;then
  # kubectl and bash completions
  if [ -x "$(command -v kubectl)" ]; then
      source <(kubectl completion bash)
      complete -F __start_kubectl k
  fi

  if ! shopt -oq posix; then
    if [ -f /etc/profile.d/bash_completion.sh ]; then
      . /etc/profile.d/bash_completion.sh
    fi
  fi
fi

# Instead I need to put this line somewhere in my zshrc 
# to have kubectl autocompletion replacing the skipped bash one:
plugins=(git git-flow brew history node npm kubectl)
# To fix error message .bash_aliases:4: parse error: condition expected: =
# Change these to this syntax to be used by zhs

# Not compatible with zsh:
if [ $HOSTNAME = "x1" ]; then

# Compatible with bash and zsh:
if [[ $HOSTNAME == "x1" ]]; then

Solution 12 - Bash

Need to create a profile for .zshrc and register the alias into it. (only if the profile isn't available)

cd ~ 
touch .zshrc && open .zshrc
add all the alias in .zshrc file
source ~/.zshrc

close and re-open terminal and run the alias.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questiono_OView Question on Stackoverflow
Solution 1 - BashShawnW.View Answer on Stackoverflow
Solution 2 - BashdsteplightView Answer on Stackoverflow
Solution 3 - Bashjson25View Answer on Stackoverflow
Solution 4 - BashAdityaView Answer on Stackoverflow
Solution 5 - Bashuser1854182View Answer on Stackoverflow
Solution 6 - BashAbramView Answer on Stackoverflow
Solution 7 - BashAntonioView Answer on Stackoverflow
Solution 8 - BashMahundView Answer on Stackoverflow
Solution 9 - BashEhsan BarkhordarView Answer on Stackoverflow
Solution 10 - BashJhamman SharmaView Answer on Stackoverflow
Solution 11 - BashjturiView Answer on Stackoverflow
Solution 12 - Bashsunny raiView Answer on Stackoverflow