How to completely remove zsh (oh-my-zsh) from Mac M1 (MacOS Monterey) - bash

I have tried to run:
uninstall_oh_my_zsh
but i get a message stating that: -bash: uninstall_oh_my_zsh: command not found
Other commands i have tried are:
chmod +x ~/.oh-my-zsh/tools/uninstall.sh
I get a response stating that: No such file or directory
sh ~/.oh-my-zsh/tools/uninstall.sh
Ran:
chsh -s /bin/bash
To change default terminal from /bin/zsh to /bin/bash
I also tried:
rm -rf ~/.oh-my-zsh
rm ~/.zshrc
cp ~/.zshrc.pre-oh-my-zsh ~/.zshrc
source ~/.zshrc
None of them have worked thus far, when i open my terminal. I get a message stating that:
The default interactive shell is now zsh.
To update your account to use zsh, please run chsh -s /bin/zsh

You don't have Oh My Zsh (a set of configuration files for zsh and a way to manage them) installed in the first place.
The warning is coming from /bin/bash itself; it's hard-coded into the executable supplied by macOS.
$ strings /bin/bash | grep "default interactive shell"
The default interactive shell is now zsh.
Though they don't say so, I suspect the warning is there because they plan to remove bash from future versions of macOS entirely. They stopped providing newer versions of bash years ago.
Your default shell is already /bin/bash; the warning is recommending that you switch to /bin/zsh.
You can continue to use bash, though I recommend installing a newer version (3.2 is old) using something like Homebrew, then changing your login shell to the new version.
However, unless you are really committed to using bash, I suggest given zsh a try.

Related

Upgrade /bin/bash on MacOS to v5+

I am trying to install Anthos Service Mesh (ASM) for a Kubeflow installation and need /bin/bash to be v5+. MacOS comes with Bash v3.2.57 which doesn't work. Simply installing Bash v5+ in "/usr/local/bin" doesn't work either as several shell scripts for the install points to "/bin/bash" and thus I still get the old version.
I had hoped I could just temporarily move the new bash v5+ to "/bin/bash" and then revert after completing the ASM install - something like this:
>>>$sudo mv /bin/bash /bin/bash_old
>>>$sudo cp /usr/local/bin/bash /bin
>>>$make install_asm
>>>$sudo mv /bin/bash_old /bin/bash
>>>mv: rename /bin/bash to /bin/bash_old: Operation not permitted
So that doesn't seem to be possible
What would be the best way to get around this? It doesn't seem to work just adding an alias to .zshrc in the hope that whenever I execute a shellscript with "#!/bin/bash" it would actually call "/usr/local/bin/bash":
~/.zshrc:
alias /bin/bash="/usr/local/bin/bash"
>>>$/bin/bash --version
>>>GNU bash, version 5.1.8(1)-release (x86_64-apple-darwin19.6.0)
test_bash.sh:
#!/bin/bash
/bin/bash --version
>>>$sh ./test_bash.sh
>>>GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin19)
Perhaps there is a way for me be permitted to move the binaries as in the example above?
By the way already the "/usr/local/bin/bash" is a link - not sure if that has any influence on what I am trying to do.
>>>$ll /usr/local/bin/bash
>>>/usr/local/bin/bash -> ../Cellar/bash/5.1.8/bin/bash
Any hints are warmly welcomed!
I used a combination of adding my new shell location to the list of approved shells in /etc/shells, then changing my user's default shell with:
chsh -s /path/to/new/bash/version
as well as making sure my new bash location was exported to the front of my path not the end, so commands looking for just any bash find that first:
export PATH=/opt/homebrew/bin/bash:$PATH
No issues with this for far but this is a new machine and I'm just getting it set-up. If you have a SHELL environment variable set in any of your bash start-up scripts make sure to change it to your new bash binary also.

Catalina bash shopt direxpand missing

I'm new to macOS coming from Windows and Linux. I want to use bash and found how to upgrade bash on Catalina, version now:
GNU bash, version 5.0.18(1)-release (x86_64-apple-darwin19.5.0), also installed coreutils.
I'm trying to set direxpand in .bashrc (which works as expected in *nix variants):
shopt -s direxpand
But when .bashrc is sourced I get an error:
-bash: shopt: direxpand: invalid shell option name
Spent a couple of hours searching online and can't find an answer, can anyone help?
Update 28/07/20 14:08 GMT
Interesting, following other advice before posting, I installed bash with brew and had to set my shell to /usr/local/bin/bash for the terminal app to use it.
So output from bash --version:
GNU bash, version 5.0.18(1)-release (x86_64-apple-darwin19.5.0)
But echo $BASH_VERSION gives:
3.2.57(1)-release
So something not right there?
Also, output from running shopt does not show direxpand.
Solved 28/07/20 20:00 GMT
For anyone with a similar problem, here's what I found.
bash installed with Catalina did not include the same shell options I have in linux.
The full solution is to install coreutils and bash with brew:
brew install coreutils bash
Then add the new version of bash to shells:
sudo vi /etc/shells add /usr/local/bin/bash
Then change your user shell:
chsh -s /usr/local/bin/bash
Then in terminal preference > general > shells open with > command (complete path) add the new bash /usr/local/bin/bash
After that shopt -s confirms that direxpand is now an option and my .bashrc works as expected.
When running shopt without arguments you can see the available shopt options you can set. In your case I expect direxpand it's not there.
The workings of the direxpand shopt option depends on the readline library. If bash is compiled without readline support this option will not be there. I expect that is the case for you.
An option would be to compile bash yourself. The accepted answer of this question will show you how to compile bash yourself. You can add the --enable-readline option in configure to force turn on readline support.
Note: compiling yourself might require you to get the readline library in your OS. I expect bash was compiled without it because it is not easily available, but that is for you to figure out.

$BASH_VERSION reports old version of bash on macOS, is this a problem that should be fixed?

I have homebrew's bash package installed. When I open a new shell:
bash --version gives GNU bash, version 5.0.7(1)-release (x86_64-apple-darwin18.5.0)
which bash gives /usr/local/bin/bash as expected.
But:
echo $BASH_VERSION yields 3.2.57(1)-release
I'm wondering if this is something I should address for scripts that might use this environment variable.
It means that the shell you're in is Bash 3.2, but bash points to Bash 5.0. Try bash and then, in the new shell, echo $BASH_VERSION – I guess it'll be 5.0. To change your login shell, add /usr/local/bin/bash to /etc/shells and change the default shell with
chsh -s /usr/local/bin/bash
sudo chsh -s /usr/local/bin/bash
After logging out and in again, $BASH_VERSION should be updated.
As for shebang lines, I recommend
#!/usr/bin/env bash
as it's portable and will use the first Bash in your $PATH.
The source of my problem was a terminal app preference setting. The "Command (complete path)" was set to /bin/bash. After setting it to "Default login shell", echo $BASH_VERSION reported the version I expected. The other problem is I stupidly ran the bash --version command in iTerm2, not terminal. So it gave a different response than what terminal would have.
Your login shell (see echo $SHELL) is probably /bin/bash and that is the one setting $BASH_VERSION. If you need to use a specific version in scripts, use the full path in the #! line.
Make sure to check that the terminal you are using is using the default login shell and not a custom one.

How to get zsh to start automatically in Mac iTerm?

I am sure this is a configuration issue, but I cannot find what is wrong. I have zsh and oh-my-zsh installed on my new Mac view homebrew.
When I start terminal it doesn't load zhs theme or autocomplete unless I run zsh command to start it. After that all works fine.
However, all the aliases I setup in .zshrc file works fine without running zsh and there is no .bashrc file in the machine.
How can I make zsh to start automatically when I open iTerm.
You can change your default shell to zsh.
Using the below command, and type your password
chsh -s /bin/zsh
If you want to use brew managed zsh, you should append /usr/local/bin/zsh to the end of file /etc/shells, then run command chsh -s /usr/local/bin/zsh.
Then reopen your iTerm2, done.

Why can't I execute a shell script using . ./test.sh?

I have a simple shell script:
#!/bin/bash
echo test
I can execute script successfully as:
./test.sh
and
source ./test.sh
However, the following throws an error:
. ./test.sh
error:
.: Command not found.
What could be causing the error? This works on el capitan (which was an upgrade) but not on sierra. Did something change with the terminal or default shell in the past few major releases?
I'm running macOS 10.12.3 with the default terminal - this is a clean install and NOT an upgrade (upgrades hang onto previous shell settings).
It sounds like you've switched your default shell to something other than bash, probably csh, where (a) . is not built-in command (only source is), and (b) even if it were, you couldn't load Bash code into the current session anyway.
To check what your default shell is, run echo $SHELL.
Run chsh -s /bin/bash to switch back to bash as your default shell.

Resources