2

I'm fairly new to Linux, as many of you may have noticed. What I speak particularly is adding personal, user-generated functions and alias in my .bashrc file. I'm not exactly sure how bash works but according to many posts I "add it to the end of my .bashrc file." Which does not work when the command is executed through the Terminal.

terdon
  • 104,119

2 Answers2

1

For login shells, .profile in your home directory will be executed. So if you have functions defined in .bashrc, make sure the file is included in .profile as below:

if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

Also, you can issue the command below:

source ~/.bashrc

and then call your functions. This will make sure there is no problem in including any files.

terdon
  • 104,119
Ashish
  • 963
0

Whenever you open a new terminal, all the commands in your .bashrc are carried out (the file is 'sourced'). If you add a new command to your .bashrc, you need to either open a new terminal or issue one of the following commands:

. ~/.bashrc
source ~/.bashrc

For example, you could put on a new line (each command has to be on a new line -- well, that's actually a simplification, but it's enough for an absolute beginner to be getting on with) at the end of your .bashrc something like:

alias hello='echo "Hello, $USER"'

...then, once you've either opened a new, fresh terminal window or used one of the source commands, you should be able to type hello and get a greeting back from your machine.

If you are doing all this and the functions/aliases don't work, then there's probably something wrong with the specific functions or aliases that you're using. If you suspect that's the case, feel free to ask a separate question.

As for tutorials, one I found very clear and useful when I was starting out with bash was linuxcommand.

evilsoup
  • 4,625