Upgrade /bin/bash on MacOS to v5+ - bash

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.

Related

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

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.

Change bash without making it default shell Mac

When running bash scripts inside zsh-Terminal I want it to use the homebrew bash version 4 instead of the default 3 of OS X.
How can I do that?
I installed bash 4 on my MacBook.
brew install bash
Instead of using it as the default shell using the following command, I want to keep my zsh.
chsh -s $(brew --prefix)/bin/bash # BAD! as I lose zsh
Still I want to run:
./my-cool-bash.sh
Use the following shebang in your scripts:
#!/bin/env bash
This makes them use the first bash in the PATH; which is the one you want.
This solution works with any Bash on any UNIX-like system.
use your new bash path:
ex, if new bash is in /usr/local/bin/
/usr/local/bin/bash my-cool-bash.sh
or write first line of script:
#!/usr/local/bin/bash
you could put an alias in your .zshrc file, something to the effect of
alias mcb='./usr/local/bin/bash/my-cool-bash.sh so that you can call it from your normal zsh whenever you want.

How do I get the .profile file to work on Solaris machine?

This has been frustrating me for two days and it seems like it should be a very simple thing. I was just created an account on a Solaris machine. Sun OS 5.10 I believe.
The default is Bourne shell which I don't want. I did a cat /etc/shells which results in:
/bin/sh
/sbin/sh
/bin/ksh
/usr/bin/ksh
Looks like Korn shell is all I can use.
I created a .profile file and wrote:
export SHELL=/usr/bin/ksh
Then I did a env and it looks like /bin/sh is still listed as my shell. I logged off, logged back on and now I get:
-sh: SHELL=/usr/bin/ksh: is not an identifier
I've tried adding #!/usr/bin/ksh at the beginning of the .profile. That didn't work. I've tried adding a semicolon at the end of the export. That didn't work. I've tried: SHELL=/bin/ksh and that didn't work either.
My end goal is to get this environment to a point where I can operate productively. I'm used to BASH where I have tab-completions, up-arrow for history, etc and this Bourne shell doesn't have any of that and it frustrates me to no end.
I know this must be simple but all my Googling comes to no avail. Can someone help me?
/etc/shells is not a standard Solaris file, you probably shouldn't rely on its contents.
On the other hand, bash is part of the default Solaris 10 installation. It should already be present as /bin/bash (/usr/bin/bash actually but /bin is a symlink to /usr/bin anyway).
If bash is not there, you might want to ask to the administrator to install the SUNWbash package from the Solaris_10/Product directory in the installation media.
Then, to update your shell, the regular way is to have the shell defined for your account updated. If it is local, that's the last field in your /etc/passwd entry.
Alternatively, you might use that hack at the end of your .profile:
[ ! "$BASH_VERSION" -a -x /bin/bash ] && SHELL=/bin/bash exec /bin/bash
In descending order of preference
ask the sysadmin to install bash and update /etc/shells and update your login shell
see if the chsh program is installed that will allow you to change your own login shell
ask the sysadmin to change your login shell to /usr/bin/ksh
modify your ~/.profile:
if type [[ >/dev/null; then
: # this is ksh
else
# not ksh
export SHELL; SHELL=/usr/bin/ksh
exec $SHELL
fi

Bad: modifier error when installing RVM

I'm trying to run source /Users/alastair/.rvm/scripts/rvm, but keep getting:
Bad : modifier in $ (").
Where would the problem be? Happy to paste other files in if these would help.
Are you in any case running a shell that is not Bash or ZSH? Bash >= 3.2.25 or ZSH >= 4.3.10 is required.
Your problem looks like you were using minimalistic shell sh which is not supported by RVM.
You can check user shell in /etc/passwd and change it with chsh -s /path/to/new/shell - list of allowed shells is available in /etc/shells - but make sure to pick Bash/ZSH, also note that links like sh->bash will not work as bash changes behavior based on the name that was invoked.

Activating a VirtualEnv using a shell script doesn't seem to work

I tried activating a VirtualEnv through a shell script like the one below but it doesn't seem to work,
#!/bin/sh
source ~/.virtualenvs/pinax-env/bin/activate
I get the following error
$ sh virtualenv_activate.sh
virtualenv_activate.sh: 2: source: not found
but if I enter the same command on terminal it seems to work
$ source ~/.virtualenvs/pinax-env/bin/activate
(pinax-env)gautam#Aspirebuntu:$
So I changed the shell script to
#!/bin/bash
source ~/.virtualenvs/pinax-env/bin/activate
as suggested and used
$ bash virtualenv_activate.sh
gautam#Aspirebuntu:$
to run the script .
That doesn't throw an error but neither does that activate the virtual env
So any suggestion on how to solve this problem ?
PS : I am using Ubuntu 11.04
TLDR
Must run the .sh script with source instead of the script solely
source your-script.sh
and not
your-script.sh
Details
sh is not the same as bash (although some systems simply link sh to bash, so running sh actually runs bash). You can think of sh as a watered down version of bash. One thing that bash has that sh does not is the "source" command. This is why you're getting that error... source runs fine in your bash shell. But when you start your script using sh, you run the script in an shell in a subprocess. Since that script is running in sh, "source" is not found.
The solution is to run the script in bash instead. Change the first line to...
#!/bin/bash
Then run with...
./virtualenv_activate.sh
...or...
/bin/bash virtualenv_activate.sh
Edit:
If you want the activation of the virtualenv to change the shell that you call the script from, you need to use the "source" or "dot operator". This ensures that the script is run in the current shell (and therefore changes the current environment)...
source virtualenv_activate.sh
...or...
. virtualenv_activate.sh
As a side note, this is why virtualenv always says you need to use "source" to run it's activate script.
source is an builtin shell command in bash, and is not available in sh. If i remember correctly then virtual env does a lot of path and environment variables manipulation. Even running it as bash virtualenv_blah.sh wont work since this will simply create the environment inside the sub-shell.
Try . virtualenv_activate.sh or source virtualenv_activate.sh this basically gets the script to run in your current environment and all the environment variables modified by virtualenv's activate will be available.
HTH.
Edit: Here is a link that might help - http://ss64.com/bash/period.html
On Mac OS X your proposals seems not working.
I have done it this way. I'am not very happy with solution, but share it anyway here and hope, that maybe somebody will suggest the better one:
In activate.sh I have
echo 'source /Users/andi/.virtualenvs/data_science/bin/activate'
I give execution permissions by: chmod +x activate.sh
And I execute this way:
`./activate.sh`
Notice that there are paranthesis in form of ASCII code 96 = ` ( Grave accent )
For me best way work as below.
Create start-my-py-software.sh and pest below code
#!/bin/bash
source "/home/snippetbucket.com/source/AIML-Server-CloudPlatform/bin/activate"
python --version
python /home/snippetbucket.com/source/AIML-Server-CloudPlatform/main.py
Give file permission to run like below.
chmod +x start-my-py-software.sh
Now run like below
.start-my-py-software.sh
and that's it, start my python based server or any other code.
ubuntu #18.0
In my case, Ubuntu 16.04, the methods above didn't worked well or it needs much works.
I just made a link of 'activate' script file and copy it to home folder(or $PATH accessible folder) and renamed it simple one like 'actai'.
Then in a terminal, just call 'source actai'. It worked!

Resources