[SOLVED] How to define bash aliases?

You have a problem with Salix? Post here and we'll do what we can to help.
User avatar
john256
Posts: 89
Joined: 1. Jun 2011, 07:52

[SOLVED] How to define bash aliases?

Post 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.
Last edited by john256 on 23. Aug 2011, 08:15, edited 1 time in total.
Shador
Posts: 1295
Joined: 11. Jun 2009, 14:04
Location: Bavaria

Re: Where to define bash aliases?

Post by Shador »

Add this to your ~/.bashrc:

Code: Select all

if [ -f ~/.bash_aliases ]; then
        . ~/.bash_aliases
fi
Image
User avatar
john256
Posts: 89
Joined: 1. Jun 2011, 07:52

Re: Where to define bash aliases?

Post by john256 »

Thank you for the suggestion, Shador, but these lines are already in ~/.bashrc.
Shador
Posts: 1295
Joined: 11. Jun 2009, 14:04
Location: Bavaria

Re: Where to define bash aliases?

Post by Shador »

Run bash -x .bashrc. Also posting the content of both files could be useful.
Image
User avatar
john256
Posts: 89
Joined: 1. Jun 2011, 07:52

Re: Where to define bash aliases?

Post 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'
Shador
Posts: 1295
Joined: 11. Jun 2009, 14:04
Location: Bavaria

Re: Where to define bash aliases?

Post 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
Image
User avatar
john256
Posts: 89
Joined: 1. Jun 2011, 07:52

Re: Where to define bash aliases?

Post by john256 »

Running

Code: Select all

set -e
. ~/.bashrc
mc
closes the terminal :(
Shador
Posts: 1295
Joined: 11. Jun 2009, 14:04
Location: Bavaria

Re: Where to define bash aliases?

Post 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).
Image
User avatar
john256
Posts: 89
Joined: 1. Jun 2011, 07:52

Re: Where to define bash aliases?

Post 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"
User avatar
john256
Posts: 89
Joined: 1. Jun 2011, 07:52

Re: [SOLVED] How to define bash aliases?

Post 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.
Post Reply