where is login bash script or ~/.profile MAC - macos

I want to install a package and in the README it says:
Add the following line to your login bash script (e.g., ~/.profile)
I cannot find any of them on my mac, where are they located?

By default bash reads only /etc/bashrc at startup on mac, but you can (and should) go ahead and create ~/.profile with whatever commands you need, and your bash session will read it at startup.
As you might expect, files in /etc/ will be executed for every user starting a bash session, whereas files in ~/ will be executed only for you.
This excellent guide explains:
http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_01.html

Related

Git bash in Windows: change the default directory when opening mintty (pwd)

I am loosing a lot of time searching in internet for the following simple setting.
I installed git (and git bash) in Windows. What I want is just to open Git Bash and be in the directory I want. I don't want to change my home directory, just be in a given directory when I open the program.
More detailed, when I open Mingw / Git bash in Windows, I would like to be in the following folder:
/c/blabla/my_git_repositories
(this corresponds to the windows-style path: C:\blabla\my_git_repositories).
At the moment, I must write the following command every time I open GitBash:
cd /c/blabla/my_git_repositories
is this possible? Which file should i modify?
Actually the program is installed here:
C:\Program Files\Git\mingw64
Thanks
If you want it happening every time you start an interactive shell, add
cd /c/blabla/my_git_repositories
to your shell startup. If your install includes the manpages say man bash and find the INVOCATION section, in a decent pager just /^INV will do it. Or Google knows to interpret a search for man bash as a search for the bash manpage.
Windows doesn't ordinarily support shell logins at all so a lot of the shell's startup-circumstance detection is overkill on Windows. Executing it is extremely fast, but describing exactly how it decides takes a page or two.
The short form is, if the startup was told it's a login shell it reads the login startup files, including (your) ~/.bash_profile, which generally should check for an interactive login and if so source the normal interactive shell startup ~/.bashrc, so ~/.bash_profile should end with something like
[[ $- = *i* && -f ~/.bashrc ]] && . ~/.bashrc
and put whatever you want in ~/.bashrc. That cd, set up your prompt colors, define your favorite shell aliases, add your personal scripts directory to PATH, whatever.
Partial solution when opening the program by clicking on a link.
Right click on the link → properties → Start in: set the value to "C:\blabla\my_git_repositories".
This will work only when you open the application from that link, but could be fine (depending by your needs).

permanently source in terminal (Mac OS)

this is probably a very basic question. I am using the bash shell still (Catalina). And I downloaded gromacs. Every time I open a new terminal window I first have to put
source /usr/local/gromacs/bin/GMXRC
in first, otherwise I will just get command not found.
How can I permanently source this so that I don't have to reenter it all the time?
I tried editing the /etc/paths file but that didn't work.
If you are still using the bash shell on macOS, all you have to do is:
Put the line:
source /usr/local/gromacs/bin/GMXRC
at the end in .bash_profile.
.bash_profile is in home directory, so you can open it like:
open ~/.bash_profile
Why .bash_profile?
.bash_profile is executed whenever a login interactive shell starts and on mac, every interactive shell is a login shell by default.
If in case you switch to zsh, instead of .bash_profile, I think .zlogin should be used.
But that would depend entirely on your need. Read about zsh configuration files in case you ever need that.

How to run ~/.bash_profile in mac terminal

So I'm installing some things for coding and personal usage, and I need to run this in the terminal (I'm on Mac if you didn't read the title).
~/.bash_profile
It just says permission denied, Im running OSX 10.8.4 Mountain Lion. How do I bypass this?
On MacOS: add source ~/.bash_profile to the end of ~/.zshrc.
Then this profile will be in effect when you open zsh.
You would never want to run that, but you may want to source it.
. ~/.bash_profile
source ~/.bash_profile
both should work. But this is an odd request, because that file should be sourced automatically when you start bash, unless you're explicitly starting it non-interactively. From the man page:
When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.
If you change .bash_profile, it only applies to new Terminal sessions.
To apply it to an existing session, run source ~/.bash_profile. You can run any Bash script this way - think of executing source as the same as typing commands in the Terminal window (from the specified script).
More info: How to reload .bash_profile from the command line?
Bonus: You can make environment variables available to OSX applications - not just the current Bash session but apps like Visual Studio Code or IntelliJ - using launchctl setenv GOPATH "${GOPATH:-}"
As #kojiro said, you don't want to "run" this file. Source it as he says. It should get "sourced" at startup. Sourcing just means running every line in the file, including the one you want to get run. If you want to make sure a folder is in a certain path environment variable (as it seems you want from one of your comments on another solution), execute
$ echo $PATH
At the command line. If you want to check that your ~/.bash_profile is being sourced, either at startup as it should be, or when you source it manually, enter the following line into your ~/.bash_profile file:
$ echo "Hello I'm running stuff in the ~/.bash_profile!"
No need to start, it would automatically executed while you startup your mac terminal / bash. Whenever you do a change, you may need to restart the terminal.
~ is the default path for .bash_profile
I was getting this error on zsh(mac os Big Sur 11.3), This is how i solved this :-
Go to Terminal.
cd /users/<yourusername>
Once you reach here issue a command :
ls -al
You will see a lot of files and one specific file .zprofile. This is your user profile. We need to edit this.
After this we need to edit the file. Issue the below command :
nano .zprofile
Once you issue this command file will be opened for edit. Add the path details for maven.
M2_PATH="/Users//code/apache-maven-3.8.1/bin" //add your path of maven diretory
PATH="${PATH}:${M2_PATH}"
export PATH
press ctrl + X and save the file.
Issue command after saving the file :
source .zprofile
Once done, you will be able to run the mvn command.
If the problem is that you are not seeing your changes to the file take effect, just open a new terminal window, and it will be "sourced". You will be able to use the proper PATH etc with each subsequent terminal window.

how to remove this [Bash], everytime I open Terminal? [duplicate]

This question already has answers here:
Error message on Terminal launch [duplicate]
(2 answers)
Closed 6 years ago.
bash: /etc/profile.d/sm.sh: No such file or directory
bash: /etc/profile.d/rvm.sh: No such file or directory
Alright guy's im close to solving my problem
I just used
sudo open /etc/profile
and I found these two lines, when i try to edit, it says you do not have permission to make changes in this file and ask for making a duplicate...
just tell me how to comment these lines with admin privileges.
Solution which worked:
"your last answer worked! I meant to say this I did:
sudo nano /etc/profile
put # before the two paths
press command x saved the file"
From the bash man page
FILES
/bin/bash
The bash executable
/etc/profile
The systemwide initialization file, executed for login shells
/etc/bash.bashrc
The systemwide per-interactive-shell startup file
/etc/bash.bash.logout
The systemwide login shell cleanup file, executed when a login shell exits
~/.bash_profile
The personal initialization file, executed for login shells
~/.bashrc
The individual per-interactive-shell startup file
~/.bash_logout
The individual login shell cleanup file, executed when a login shell exits
~/.inputrc
Individual readline initialization file
You will want to check the systemwide files and see if they are referencing rvm. If you are the only user on your system (it is your workstation or your home computer), feel free to modify these files to remove the rvm reference (assuming you aren't using rvm anymore). Otherwise, ask your system administrator to fix the execution environment.
More information on rvm can be found here, and your online manual pages can provide more details about what files bash reads by default.
Failing all of the above, a quick and dirty hack would be to execute
touch /etc/profile.d/rvm.sh
as a user with the appropriate permissions.

Getting -bash: mvn: command not found

I tried setting the Maven PATH in .profile file as well using export commands in terminal(Mac OSX). But, on running mvn commands, getting -bash: mvn: command not found
Please help.
What did you set up exactly? Did you setup PATH like this (or something equivalent):
export PATH=$PATH:...:$M2_HOME/bin
If yes, did you logout and login again? According to the bash manpage:
When bash is invoked as an interactive
login shell, or as a non-interactive
shell with the --login option, it
first reads and executes commands from
the file /etc/profile, if that file
exists. After reading that file, it
looks for ~/.bash_profile,
~/.bash_login, and ~/.profile, in that
order, and reads and executes commands
from the first one that exists and is
readable. The --noprofile option may
be used when the shell is started to
inhibit this behavior.
...
When an
interactive shell that is not a login
shell is started, bash reads and
executes commands from
/etc/bash.bashrc and ~/.bashrc, if
these files exist. This may be
inhibited by using the --norc option.
The --rcfile file option will force
bash to read and execute commands from
file instead of /etc/bash.bashrc and
~/.bashrc.
As you can see, commands from .profile are not executed for a non-login shell (the type of shells you open after logging in). So you have to logout/login or to source the file manually to take your setup into account. See this blog post for more details.
Have you installed Maven, already? If you use MacPorts to install Maven, you won't need to edit your PATH.

Resources