3

Hi I am having a problem with setting alias in mac after I start the screen command, I have alias for working with git, like

commit=git commit

they work as I expect when I start my terminal (iTerm2), but then sometimes I use screen to have simultaneous instances in remotes servers and virtual machines I work with. After this the alias disappear(command not found).

Does anyone know why or how solve it?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

2 Answers2

4

To make the alias work, you must use the alias command. For example, to create an alias in Bash you do:

$ alias commit="git commit"

This works temporarily ie.: in your current shell. In order to make it "stick", you must put it in your ~/.bashrc. That will make it be sourced to all instances of Bash you'll invoke during your terminal session.

When you start screen, it starts a separate Bash too, so you'll be covered.

You write something about VMs. If you need this alias to work there, you must make ~/.bashrc on these VMs to have the same aliases. But that's the other story. You should already know how to achieve what you want.

  • yes I know what you mean, I wanted to be quick, my alias are in .bash_profile, which has higher priority that .bashrc – Roger Rodriguez Texido Mar 18 '16 at 18:53
  • The problems with ``.bash_profile`` and ``.bashrc`` I typically debug by putting ``echo I_AM_IN_BASH_RC`` printout and figuring out whether this ``echo`` gets executed when you start ``screen``. If you don't see it, your file is simply not sourced somehow. – Wojciech Adam Koszek Mar 18 '16 at 19:03
  • Thanks, I thought both of them we're being loaded, but just .bashrc was, I put my alias there and it's working fine. Thank you. – Roger Rodriguez Texido Mar 18 '16 at 19:52
1

You need to make sure your aliases are defined in ~/.bashrc to ensure they get included in all logins. You can test this out: edit your ~/.bashrc to include this line:

echo "bashrc"

And then edit your ~/.bash_profile to include this line:

echo "bash_profile"

You'll see when you start screen that only "bashrc" is displayed.

See this question for much more detail on the subject.

Community
  • 1
  • 1
miken32
  • 42,008
  • 16
  • 111
  • 154