bash_profile file is not is not being sourced in a macOS zsh shell. Now whenever you start a new terminal session, your . zprofile file should be automatically sourced.
In short, you are putting your aliases in the wrong file . bashrc , that is why you need to keep running source to get the aliases working in any new login terminal instances.
The . bash_profile file is a personal initialization file for configuring the user environment. The file is defined in your home directory and can be used for the following: Modifying your working environment by setting custom environment variables and terminal settings.
bash_profile contains lines like below that source the . bashrc file. This means each time you log in to the terminal, both files are read and executed. Most Linux distributions are using ~/.
Now that we've narrowed down the problem:
ps -p $$
at the command line to determine that you are, in fact, using a bash shell. .zshrc
..bash_profile
to .zsh
, OR.zshrc
to directly source your .bash_profile
.UPDATE: Do what @TC1 mentions in the comments and keep the shell-specific code in each shell's own profile, and from those profiles, only source shell-agnostic code.
On Mac Catalina, I just had to open "preferences" on terminal and change the "shells open with" from "default" to "Command(complete path)", which the default path was "/bin/zsh". touch ~/.zshrc
, if that file doesn't exist already, and copy/paste your stuff from ".bash_profile" into the ".zshrc" file.
bash_profile.sh
is applicable for bash
shell.
if your default shell is not bash
and if your default shell is someother shell for example zsh
then you have to manually load the .bash_profile
using source ~/.bash_profile
.
You can always change the default shell to bash
shell so that the .bash_profile
file will be automatically loaded.
Inorder to automatically load .bash_profile
, you can update your default shell to bash
using the command chsh -s /bin/bash
cat /etc/shells
will list the default shells available in the machine
echo $SHELL
will display the currently active shell in your machine
To change active shell to a different shell, use
chsh -s /bin/bash
. Thenecho $SHELL
to verify if the shell has changed.
Terminal -> Preference -> profile -> Shell -> Run command : source ~/.bash_profile
Tick on run inside shell.
After doing all those , just logout and check weather everything works fine or not
I tried the approved answer. Changing the .zshrc file works for one of my machines. But for the other one, when I run ps -p $$, it is -sh under the command. And I changed both bash and zsh files, neither of them works for me this time.
So I found this https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html
it mentioned "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. "
so I went to that file /etc/profile and add "source ~/.bashrc" in that file. Then it works since every time a terminal is opened, it runs the command in that /etc/profile file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With