How do I make my bashRC source permanent? [duplicate] - bash

This question already has answers here:
OSX Terminal not recognizing ~/.bashrc and ~/.bash_profile on startup
(1 answer)
What's the difference between .bashrc, .bash_profile, and .environment?
(7 answers)
Closed 3 years ago.
When I make my bashRC file with nano ~/.bashrc.
With only one alias:
alias c="clear"
I only can use the alias if I enter source ~/.bashrc or use . ~/.bashr, but I want this source to carry over to new terminal windows. Is there away to make this the default source? Or is there another way to make the bashrc permanent?

Add it to .bash_profile.
.bashrc is for noninteractive logins
if you are opening a new window and logging in manually you need to add it to .bash_profile

Related

Can someone explain the difference between .bashrc and .bash_profile? [duplicate]

This question already has answers here:
What's the difference between .bashrc, .bash_profile, and .environment?
(7 answers)
Closed 3 years ago.
Can someone explain the difference between .bashrc and .bash_profile?
Examples would be great.
Thank you.
/.bashrc and ~/.bash_profile are scripts that might be executed when bash is invoked. The ~/.bashrc file gets executed when you run bash using an interactive shell that is not a login shell.
So basically bashrc is run when you run an interactive shell that you're not logged in for and bash_profile is executed when you are a logged in user.
Have a further read here: https://www.quora.com/What-is-bash_profile-and-what-is-its-use

bash alias disappears when opening new terminal [duplicate]

This question already has answers here:
Should aliases go in .bashrc or .bash_profile? [duplicate]
(4 answers)
Closed 4 years ago.
im setting up a new alias by typing this command:
vi ~/.bashrc
and then placing my alias:
alias school='ssh -Y username#linux.student.cs.uwaterloo.ca'
followed by exiting the file using: wq
however when i close my terminal and open my terminal, i get a "command can't be found." error message.
if i type source ~/.bash_aliases, it will work, the alias will work, but when i open a new terminal it won't.
is my .bashrc supposed to be empty when i vi into it?
The reason your alias is getting lost is because you dont have your bashrc sourced in a new terminal.
Same will happen even if you create a new alias file and source it in bashrc because its scope gets limited to the terminal you are editing in.
What you can do is logout once and then log in back so that bashrc entries gets updated for your user account or you can source in each terminal by typing
source ~/.bashrc
By adding the same entry to '''.profile''' you are making sure the alias is set on each system boot.
So its better to set the alias in .bashrc rather than .profile
Another major point to nite here is to make sure you dont delete anything in bashrc since that will do catastrophic changes to you session.

Alias not working in Ubuntu 14.04 [duplicate]

This question already has answers here:
How to set an alias inside a bash shell script so that is it visible from the outside? [duplicate]
(4 answers)
How to reload .bashrc settings without logging out and back in again?
(18 answers)
Closed 6 years ago.
So I have added an alias for jumping to another directory like this
in my ./bashrc file , Looks like this
alias crmx="cd /var/www/crm/website-crm/"
Then i saved the file
but when I try to run
crmx
it says
command not found
Also I tried to do alias to see all the command but my command is not listed
Any idea ?
The file is ~/.bashrc (starting with a dot).
And you have to source it (reload) by doing source ~/.bashrc or just by closing and reopening your terminal.
You can also type ps to check if your shell is bash (for example if it's zsh you have put your alias in the ~/.zshrc file)
Let's suppose you are on bash.
Once you saved that file, you have to have bash read it with a command like this:
. ~/myaliasfile
or like this
source ~/myaliasfile
if the file resides in your home directory. Specify the path (relative to your home or absolute) otherwise.
Then you'd go to your .bashrc file and add the very same line to the end of it. By doing so the alias(es) will be read and made available to every single bash invocation and login.
Done!
More details here and here.

vim - run :!commands in my .bashrc [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Commands executed from vim are not recognizing bash command aliases
Why doesn't my vim know my alias?
say I set
alias kapow='grep'
in my .bashrc, which I source after.
I open vim, type
:!kapow "dude"
but vim tries to run /bin/bash kapow, when I actually wanted it to run my alias.
How does one run commands from a bashrc inside of vim (without leaving to the :shell)?
The vim manual says this about :!
On Unix the command normally runs in a non-interactive shell. If you want an interactive shell to be used (to use aliases) set 'shellcmdflag' to "-ic".

restore PATH under Mac OS X [duplicate]

This question already has an answer here:
How to restore .bash_profile on a mac? None of my unix terminal are working [closed]
(1 answer)
Closed 6 years ago.
Hi guys I tried to add new directory to the PATH, but instead appending I overwrote it. Is there any way to restore those default paths?
If you changed your PATH in a Terminal shell, simply close that Terminal window and open a new one. Changes to environment variables are local to the shell in which you change them (and any subshells created by that one).
Just restart your terminal that will assign variables based on your .profile or .bashrc ( if you are running bash )

Resources