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

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

Related

Why is conda not activating my environment in this shell script? [duplicate]

This question already has answers here:
Conda command working in command prompt but not in bash script
(4 answers)
Closed 2 years ago.
Here is my script. I have an env called myenv previously setup.
I know that I'm sourcing conda correctly, becuase if I deliberately hand the script a bad environment name, it outputs an error message. But if I call it with myenv, it runs but doesn't do anything. My environment stays as (base).
#!/bin/zsh
# MAKE SURE YOU HAVE MINICONDA INSTALLED
CONDA_BASE=$(conda info --base)
source $CONDA_BASE/etc/profile.d/conda.sh
conda activate myenv
I'm using MacOS Catalina. Everything else is set up correctly, and every other conda command works. The only reason I can think of is that my shell is for some reason cancelling the command... It's a bit baffling.
I'd appreciate any help with this issue.
For your script to modify the state of your interactive shell, you need to either source it into your interpreter, or define it as a function rather than a script at all.

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

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

Bash error after opening Terminal and running shell scripts (CentOS) [duplicate]

This question already has answers here:
Error message on Terminal launch [duplicate]
(2 answers)
Closed 6 years ago.
Every time I open Terminal in CentOS 6.4, I get the error:
bash: usr/local/bin: No such file or directory
I've checked .bashrc and .bash_profile to see if there are any lines that reference usr/local/bin, but haven't found anything. The same error also appears when I switch to root, or run a shell script.
Is it as simple as adding a backslash in front of usr? Like so--
/usr/local/bin
Still don't know where the error is happening though. Any help is much appreciated. Thanks!
This is strange as the normal bash directory on a centos 6.4 system is /bin/bash, however I would advise you to check the following:
echo $SHELL
It should pull your SHELL environment variable to show you where what shell you are using, normally it looks like this:
SHELL=/bin/bash
If it's different say for example:
SHELL=usr/local/bin/bash
then I would check your passwd file to make sure your users default shell is pointing to the right place.
username:x:601:601::/home/username:/bin/bash
Also I would suggest check where you shell actually lives
which bash
/bin/bash
And make sure everything is pointing to the correct location.

Running a command behind BASH prompt in bashrc [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Start background process from .bashrc
I'm executing a script in .bashrc and the user prompt will not appear until all commands have executed. Is there a way, on launching a terminal, that the prompt appears while the commands execute in the background?
Thanks for any assistance!
append & to your command to have it run in the background.

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".

Resources