Page 1 of 2

[SOLVED] How to define bash aliases?

Posted: 22. Aug 2011, 20:23
by john256
I have problems setting some handy bash aliases. Creating ~/.bash_aliases and placing the desired aliases therein seems not to work. Can anyone point me in the right direction?

Edited title to make it more informative and to indicate that the issue has been resolved.

Re: Where to define bash aliases?

Posted: 22. Aug 2011, 21:03
by Shador
Add this to your ~/.bashrc:

Code: Select all

if [ -f ~/.bash_aliases ]; then
        . ~/.bash_aliases
fi

Re: Where to define bash aliases?

Posted: 22. Aug 2011, 21:05
by john256
Thank you for the suggestion, Shador, but these lines are already in ~/.bashrc.

Re: Where to define bash aliases?

Posted: 22. Aug 2011, 21:08
by Shador
Run bash -x .bashrc. Also posting the content of both files could be useful.

Re: Where to define bash aliases?

Posted: 22. Aug 2011, 21:20
by john256
My ~/.bashrc is the default one:

Code: Select all

export PS1='\u[\W]\$ '
export PAGER="most"

if [ -f ~/.bash_aliases ]; then
        . ~/.bash_aliases
fi
And ~/.bash_aliases contains:

Code: Select all

alias 'mc=mc -b'
Running bash -x .bashrc sems to indicate that ~/.bash_aliases is being read, but the alias don't work:

Code: Select all

+ export 'PS1=\u[\W]\$ '
+ PS1='\u[\W]\$ '
+ export PAGER=most
+ PAGER=most
+ '[' -f /home/john/.bash_aliases ']'
+ . /home/john/.bash_aliases
++ alias 'mc=mc -b'

Re: Where to define bash aliases?

Posted: 22. Aug 2011, 21:37
by Shador
john256 wrote:Running bash -x .bashrc sems to indicate that ~/.bash_aliases is being read, but the alias don't work:
That's natural. We start a new bash session here, which returns after running .bashrc to the current on, but the current session where you run that command doesn't get affected.
Now try this:

Code: Select all

set -e
. ~/.bashrc
mc

Re: Where to define bash aliases?

Posted: 22. Aug 2011, 21:39
by john256
Running

Code: Select all

set -e
. ~/.bashrc
mc
closes the terminal :(

Re: Where to define bash aliases?

Posted: 22. Aug 2011, 22:46
by Shador
john256 wrote:Running

Code: Select all

set -e
. ~/.bashrc
mc
closes the terminal :(
oops, replace -e with -x (I always mix them up :D). Anyway this indicates one of the commands called by .bashrc is returning non-zero (i.e. probably failing).

Re: Where to define bash aliases?

Posted: 23. Aug 2011, 08:13
by john256
Thank you for the hint, Shador! It turned out that the alias had a wrong format.

It should have been:

Code: Select all

alias mc="mc -b"

Re: [SOLVED] How to define bash aliases?

Posted: 24. Aug 2011, 18:14
by john256
I found, however, that this don't work if the XFCE Terminal is set to run as a login shell. Does anybody know how to make bash_aliases to work in this case?

Edit: I need the option "Run command as login shell" because it enables colored output defined in ~/.dir_colors. If this can be accomplished without running the terminal as login shell, I would greatly appreciate hints in that direction.