I have created an alias and appended to ~/.bashrc:

echo "alias mydir='cd /home/agochar/Desktop/folder'">>~/.bashrc

When I tried to run it like: mydir it says: Command 'mydir' not found

But when I just run .bashrc like: . ~/.bashrc it works fine but not in a normal way.
Saying normal way I mean when we open terminal emulator it prompts: username@hostname$ and we start typing commands. But what the heck is this:

\[\e]0;\u@\h: \w\a\]\[\033[;32m\]┌──(\[\033[1;34m\]\u㉿\h\[\033[;32m\])-[\[\033[0;1m\]\w\[\033[;32m\]]\n\[\033[;32m\]└─\[\033[1;34m\]$\[\033[0m\]

When I type mydir it works. The solution I want is I want mydir working without runing . ~/.bashrc each time I want it to use. Also to get rid of these escape sequence like character when I execute . ~/.bashrc.

  • 2
    If you don't want the alias to be created by sourcing your ~/.bashrc file, why did you put it in your ~/.bashrc file? When you invoke a new bash process, it will automatically source your ~/.bashrc file. Are you saying that closing your terminal window and opening another (which invokes a new shell process) does not create your alias in the new window? If it doesn't, are you perhaps using a different shell for your user account, one that doesn't read bash startup files like ~/.bashrc?
    – Sotto Voce
    Nov 20 at 1:54
  • It is not even creating alias in the same login session. I am just the beginner and somewhere I have read that after creating alias you need to . ~/.bashrc(being new I am not too sure that what does it do?) but which I run . ~/.bashrc and just type command mydir it worked. I am confused with those \e \w \a like character, wondering what just happened. And after while I close and open the terminal window again it is not working? Nov 20 at 4:44
  • 1
    Sounds like your account in Linux is using a different shell that doesn't read the ~/.bashrc that's specific to bash. Please edit your question to include the output from this command: ps $$
    – Sotto Voce
    Nov 20 at 5:42
  • It is unwise just to append to .bashrc. It is a script in its own right -- the standard one in my Mint is 125 lines. It has conditions, like an early return for non-interactive shells. It actually looks for (and uses) an alternative ~/.bash_aliases file, just so you don't have to hack the (sensitive) bashrc file, or re-add all your aliases when you install a new base version. Nov 20 at 10:33
  • @SottoVoce The output of the command ==> 1395 pts/0 Ss 0:00 /usr/bin/zsh Nov 21 at 2:23


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.