[SOLVED] How to define bash aliases?
[SOLVED] How to define bash aliases?
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.
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.
Re: Where to define bash aliases?
Add this to your ~/.bashrc:
Code: Select all
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
Re: Where to define bash aliases?
Thank you for the suggestion, Shador, but these lines are already in ~/.bashrc.
Re: Where to define bash aliases?
Run bash -x .bashrc. Also posting the content of both files could be useful.
Re: Where to define bash aliases?
My ~/.bashrc is the default one:
And ~/.bash_aliases contains:
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]\$ '
export PAGER="most"
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
Code: Select all
alias 'mc=mc -b'
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?
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.john256 wrote:Running bash -x .bashrc sems to indicate that ~/.bash_aliases is being read, but the alias don't work:
Now try this:
Code: Select all
set -e
. ~/.bashrc
mc
Re: Where to define bash aliases?
Running
closes the terminal
Code: Select all
set -e
. ~/.bashrc
mc
Re: Where to define bash aliases?
oops, replace -e with -x (I always mix them up ). Anyway this indicates one of the commands called by .bashrc is returning non-zero (i.e. probably failing).john256 wrote:Runningcloses the terminalCode: Select all
set -e . ~/.bashrc mc
Re: Where to define bash aliases?
Thank you for the hint, Shador! It turned out that the alias had a wrong format.
It should have been:
It should have been:
Code: Select all
alias mc="mc -b"
Re: [SOLVED] How to define bash aliases?
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.
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.