source /.bash_profile command provide error - bash

I run the command source ~/.bash_profile and get the following error:
$ source ~/.bash_profile
-sh: /Users/chaklader/.sdkman/contrib/completion/bash/sdk: line 37: syntax error near unexpected token `<'
-sh: /Users/chaklader/.sdkman/contrib/completion/bash/sdk: line 37: ` done < <(curl --silent "${SDKMAN_CANDIDATES_API}/candidates/all")'
The login shell that I use is bin/sh:
Whats the issue here and how to solve it?

This is how I solved the issue with the provided steps:
Install Homebrew from the docs on their homepage
Install Git using Homebrew (optional, but nice to have a more up-to-date git)
brew install git
Now install bash:
brew install bash
Add this install of bash to the allowed shells list:
echo '/usr/local/bin/bash' | sudo tee -a /etc/shells;
Homebrew installs things to /usr/local/Cellar/ by default, then symlinks any binaries to /usr/local/bin, so you've now got the latest bash sitting at /usr/local/bin/bash
Finally, change your shell to use this new one:
chsh -s /usr/local/bin/bash
Open a new terminal window/tab, and run these commands to double-check your work:
$ echo $SHELL
/usr/local/bin/bash
$ echo $BASH_VERSION
5.1.8(1)-release
This also solved the issue for running the source ~/.bash_profile whenever I open a new window in the terminal.
Reference:
The answer is from here How do I install Bash >= 3.2.25 on Mac OS X 10.5.8? by user jeffbyrnes

Related

Can't find nix-env or nix-build on MacOS Catalina

I can't find nix-env, nix-build, nix-shell etc. on MacOS Catalina.
I installed with:
sh <(curl https://nixos.org/nix/install) --darwin-use-unencrypted-nix-store-volume
and was able to run them yesterday. I restarted my computer and can no longer find them. find / -name nix-env | grep nix-env shows nothing.
I tried installing again with the same command (sh <(curl https://nixos.org/nix/install) --darwin-use-unencrypted-nix-store-volume) but this time it exists immediately with 0 status code.
I suspect I need to do something to mount a virtual drive.
You should follow Notes on the recommended approach.
It looks like the volume is not mounted (check /etc/fstab state with vifs as described in documentation).
Use the Disk Utility UI to remove the nix volume (sudo rm -rf /nix won't work).
Then run the script again and cross fingers your fingers this time: sh <(curl https://nixos.org/nix/install) --darwin-use-unencrypted-nix-store-volume
While Nix (amongst others) installs with bash newer MacOS do use zsh instead of bash.
So you need to update your .zshrc to source this command from bash, too.
In your terminal start editing with:
sudo nano ~/.zshrc
and add:
source ~/.nix-profile/etc/profile.d/nix.sh
Reload and test with
source ~/.zshrc; nix --version

oh-my-zsh does not start on mac

I installed oh-my-zsh as suggested in http://ohmyz.sh/.
FYI,
[~]$ zsh --version
zsh 5.0.8 (x86_64-apple-darwin15.0)
[~]$ echo $SHELL
/bin/zsh
[~]$ ls .oh-my-zsh/
LICENSE.txt cache lib oh-my-zsh.sh templates tools
README.md custom log plugins themes
Only when I type "zsh" then I can see the oh-my-zsh prompt like:
[~]$ zsh
➜ ~
Also, I tried to change my default shell to zsh:
[~]$ chsh -s /bin/zsh
Changing shell for myUserName.
Password for myUserName:
chsh: no changes made
How can I use directly oh-my-zsh whenever I start mac terminal?
Not only in System Pref>User and Group>...>User profile's shell settings, but also in Mac's terminal>Preference>ChosenProfile>Shell section, I had to change /bin/bash to /bin/zsh. after that, it works! Thank you, #RemyJ!
You have to change the default shell to zsh.
To do so use the following command.
chsh -s /bin/zsh
restart your terminal
I took it from here.
These were the steps I followed when I installed zsh.
I hope it will help you as well.
Run the following in the terminal:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Also, I tried to change my default shell to zsh:
[~]$ chsh -s /bin/zsh
try
chsh -s $zsh
that worked fine for me
I had a similar issue but I resolved it by executing the command chsh -s /bin/zsh in the terminal,then navigated to
Terminal -> Preferences -> General window
and changed the Shells open with: option to Default login shell while the command (complete path) set to /bin/zsh.This should solve your problem.

"rvm use --install" broken in Jenkins, "uname: command not found"

This is a snippet from a Jenkins job run that needs rvm 1.9.3.. I have no idea why the PATH is not being looked at. From this build the PATH environment variable looks correctly set as PATH="/usr/java/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" (as set in /etc/environment), HOME="/scratch" and SHELL="/bin/sh", so I'm mystified by this.
$ bash -c " source ~/.rvm/scripts/rvm && rvm use --install --create ruby-1.9.3 && export > rvm.env"
/scratch/.rvm/scripts/rvm: line 12: uname: command not found
/scratch/.rvm/scripts/rvm: line 15: ps: command not found
bash: rvm: command not found
I have also attempted the rbenv route but am met with similar errors indicating the absence of $PATH
Also, the Jenkins user belongs to the rvm group.
I send many internets in thanks for any assistance offered!
rvm needs login shell.
I use it like this in my builds:
echo "rvm install 2.2.3" | /bin/bash -l
Works just fine this way.

How to add bash command completion for Docker on Mac OS X?

I am running docker and I want bash command completion for docker commands and parameters.
If you have already homebrew bash-completion installed just install the docker completion script into the bash_completion.d
curl -XGET https://raw.githubusercontent.com/docker/cli/master/contrib/completion/bash/docker > $(brew --prefix)/etc/bash_completion.d/docker
Note: If you do not have homebrew bash-completion installed, follow these instructions to install it before you execute the line above.
Note: the completion depends on some functions defined in debian bash-completion. Therefore, just sourcing the docker completion script as described in completion/bash/docker may not work. If you try to complete docker run (by hitting TAB) you may get an error like __ltrim_colon_completions: command not found. This could mean that you have not installed the bash-completion scripts.
The official Docker for Mac page has a section on installing bash completion:
https://docs.docker.com/docker-for-mac/#bash
If you have Homebrew bash completion installed:
cd /usr/local/etc/bash_completion.d
ln -s /Applications/Docker.app/Contents/Resources/etc/docker.bash-completion
ln -s /Applications/Docker.app/Contents/Resources/etc/docker-machine.bash-completion
ln -s /Applications/Docker.app/Contents/Resources/etc/docker-compose.bash-completion
The completion scripts come with Docker Beta. I want them to stay up to date. So, on OS X...
Install homebrew's bash-completion
Symlink the files
find /Applications/Docker.app \
-type f -name "*.bash-completion" \
-exec ln -s "{}" "$(brew --prefix)/etc/bash_completion.d/" \;
The stumbling point for me was that once you brew install bash-competion, you have to add few lines in your .bash_profile to load it once you launch Terminal:
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
Source:
http://davidalger.com/development/bash-completion-on-os-x-with-brew/
Because I haven't found anywhere a step by step documentation, I've made a quick script to install homebrew, bash-completion and eventually the completion scripts for docker.
https://github.com/HypnoTheNomad/docker-bash-completion-macos-brew
The auto completion of docker needed not only for mac, its also needed for ubuntu / bash terminals.
In Ubuntu
curl -ksSL https://raw.githubusercontent.com/docker/cli/master/contrib/completion/bash/docker |sudo tee /etc/bash_completion.d/docker
Completion will be available upon next login.
Since its top result in google I added answer here.
The official Docker site has a section for Command-line completion, and for Mac to:
https://docs.docker.com/compose/completion/#mac
Helped for me with Homebrew:
brew install bash-completion
After the installation, Brew displays the installation path. From documentation is correct for me:
/usr/local/etc/bash_completion.d/
Run the script:
sudo curl -L https://raw.githubusercontent.com/docker/compose/1.25.4/contrib/completion/bash/docker-compose -o /usr/local/etc/bash_completion.d/docker-compose
Open and add following in the end of your file ~/.bash_profile:
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
Restart terminal. It's all.
Guide to setup autocomplete for ZSH on Mac OSX
Follow these steps if you are using oh-my-zsh and autocomplete is not working:
Step 1:
Make the following three links:
ln -s /Applications/Docker.app/Contents/Resources/etc/docker.zsh-completion /usr/local/share/zsh/site-functions/_docker
ln -s /Applications/Docker.app/Contents/Resources/etc/docker-compose.zsh-completion /usr/local/share/zsh/site-functions/_docker-compose
Step 2:
Either add autoload -Uz compinit; compinit to .zshrc
or run echo "autoload -Uz compinit; compinit" >> .zshrc in your shell
Just to be said:
if you use brew:
brew install docker
will do all what you need. It includes brew link docker which installs the completion into `brew --prefix`/etc/bash_completion.d/docker
same topic, same answer for docker-machine, docker-compose, etc. ...
else (perhaps you are using Docker Beta (new "more native" docker installation package without Virtualbox) you still have to add it manually, then follow Michael's answer plus have a look at the additional completion scripts for docker-machine, docker-compose and some shell-helper that are handled in the 'script' from CodeCorrupt

Is there a way to fix this error in terminal: -bash: HOME/.rvm/scripts/rvm: No such file or directory?

I'm new to Ruby and just installed it following the instructions on this website.
I'm not sure why, but now whenever I open terminal, I get the following error message:
-bash: HOME/.rvm/scripts/rvm: No such file or directory
Is there something I'm missing? As far as I can tell, Ruby is installed correctly and is running fine.
It looks like you put HOME in your .bash_profile instead of $HOME. You should also verify that your .rvm directory exists in your home directory. You could also check the value of $HOME by running echo $HOME in a shell, and it should return something like /home/yourname.
Note: You could change "$HOME" to "~".
This maybe solve your problem:
Before you install RVM, you can input this in your terminal to check server key:
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
Then you can input the following command to install rvm
curl -L https://get.rvm.io | bash -s stable
Just have a try~
You must source the rvm scripts so that they are available to your terminal session
source /usr/local/rvm/scripts/rvm
source ~/.rvm/scripts/rvm
You may want to add it to your .bash_profile or .bashrc file so that they are executed every time you load a terminal window like so:
$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> .bashrc

Resources