'scl enable' not setting PATH with bash - bash

I'm trying to use software collections on CentOS 6.8 server, but it won't set the environment variable PATH corectly if the command passed is "bash", but "tcsh" works... (however we don't use tcsh on this machine)
Example:
$ scl --list
devtoolset-4
python27
rh-java-common
rh-perl524
rh-python35
$ which python
/usr/bin/python
$ python --version
Python 2.6.6
$ scl enable python27 bash
$ which python
/usr/bin/python
$ python --version
Python 2.6.6
$ cat /opt/rh/python27/enable
export PATH=/opt/rh/python27/root/usr/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/opt/rh/python27/root/usr/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export MANPATH=/opt/rh/python27/root/usr/share/man:${MANPATH}
# For systemtap
export XDG_DATA_DIRS=/opt/rh/python27/root/usr/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}
# For pkg-config
export PKG_CONFIG_PATH=/opt/rh/python27/root/usr/lib64/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}
$ echo $PATH
/usr/share/gridengine/bin/lx26-amd64:/usr/lib64/qt-3.3/bin:/usr/NX/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/bin:/opt/maker/bin:/opt/tools/:/opt/tools/amos-3.1.0:/opt/mpich-install/bin:/opt/pssc/bin:/opt/torque/bin:/opt/torque/sbin
$ echo $LD_LIBRARY_PATH
/opt/rh/python27/root/usr/lib64
$ echo $MANPATH
/opt/rh/python27/root/usr/share/man::/opt/mpich-install/share/man:/opt/mpich-install/share/man
So why is MANPATH and LD_LIBRARY_PATH being set properly but not PATH? If i use tcsh it works as expected:
$ scl enable python27 tcsh
$ which python
/opt/rh/python27/root/usr/bin/python
$ python --version
Python 2.7.8

Thank you Dominic you were on to something. I originally checked ~/.bash* files as well as /etc/bash* and /etc/profile but after your comment, I found several scripts in /etc/profile.d/ that we being executed, and one of them set the PATH explicitly without appending. I added $PATH back in there and now scl enable is working as expected!

Related

How to Install Homebrew on Windows WSL Ubuntu, and fix "zsh: brew command not found" error

Installation was a series of 5 simple steps:
first, install homebrew itself from command in the home page:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
After that, following instructions in this page, and changing ~/.bash_profile to ~/.profile as I am using Ubuntu as my wsl distro, i had to give these commands:
test -d ~/.linuxbrew && eval $(~/.linuxbrew/bin/brew shellenv)
test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
test -r ~/.profile && echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile
echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile
But now, when I try to run brew, I get command not found error.
In a wsl environment, brew is installed at location: /home/linuxbrew/.linuxbrew/ which is not part of the path.
So we simply need to add that to path, and it works. I am using zsh as my shell, so I add these lines to my ~/.zshrc file (in ubuntu file system) :
export BREW_HOME="/home/linuxbrew/.linuxbrew/bin"
export PATH="$PATH:$BREW_HOME"
if you happen to need to share your .zshrc across different OS, you can do some OS check in your zshrc file to see if it is macOS or linux/wsl:
case `uname` in
Linux)
## add brew home to PATH in linux/WSL
brew_home=/home/linuxbrew/.linuxbrew
if [ -d "${brew_home}" ]; then
export PATH=${brew_home}/bin:$PATH
fi
javac_loc=/usr/bin/javac
if [ -x "$javac_loc" ]; then
export JAVA_HOME=$(readlink -f $(dirname $(readlink -f $javac_loc)))
fi
;;
Darwin)
## Do macOS thing...
export JAVA_HOME=$(/usr/libexec/java_home)
;;
esac

Ubuntu 19.10 .. can't change shell to zsh

I'm trying various things but I can't change shell to zsh in Ubuntu 19.10 x64 on my MacBook Pro 2012 with 16 GB RAM.
$ which zsh # Output: /usr/bin/zsh
$ zsh --version # Output: zsh 5.7.1 (x86_64-ubuntu-linux-gnu)
$ chsh -s $(which zsh)
It makes changes to /etc/passwd file but when I run
$ echo $SHELL
It still gives me /bin/bash.
What am I doing wrong?

Unable to modify /etc/shells on macOS to include brew installed version of bash

I am trying to update my /etc/shells file to include the path to a homebrew installed version of bash which resides at /usr/local/bin/bash
$ sudo echo /usr/local/bin/bash >> /etc/shells returns Permission denied and attempting to manually update is not allowed as it appears to be read-only.
Upon inspecting the file, the permissions are set as follows:
-rw-r--r-- 1 root wheel 179 Feb 21 2017 /etc/shells
So, with this in mind, and after looking at this article about Updating you shell with Homebrew I tried to initiate a shell as the root user and then try command above, i.e:
$ sudo -s
$ echo /usr/local/bin/bash >> /etc/shells
$ chsh -s /usr/local/bin/bash
However, this seems to hang on the first command ($ sudo -s). This spawns a bash process that eats up ~ 70% CPU and nothing happens.
Is there an alternative way one can update the /etc/shells/ file?
An approach to adding to a root-only file is echo /usr/local/bin/bash | sudo tee -a /etc/shells.
– Petesh
Would you be able to explain why that works and the sudo echo /usr/local/bin/bash >> /etc/shells does not though.
The latter doesn't work because the output redirection >> is (tried to be) applied by the shell before the sudo … is executed, and of course the user shell has no permission to do that.
Or you can just use this (I had to do this on macOS Mojave):
sudo sh -c "echo $(which zsh) >> /etc/shells"
chsh -s $(which zsh)

How do I set env variables in bash script for a packer image

I am trying to bake an AMI with Maven and Gradle in Packer. Below is my json file.
#!/bin/bash
sudo yum -y update
sudo yum install -y httpd
sudo mkdir -p /usr/local/apache-maven
cd /usr/local/apache-maven
sudo wget http://mirror.olnevhost.net/pub/apache/maven/binaries/apache-maven-3.2.2-bin.tar.gz
sudo tar xvf apache-maven-3.2.2-bin.tar.gz
echo "Maven is installed at usr local apache-maven #maven"
sudo mkdir /opt/gradle
cd /opt/gradle
sudo wget https://services.gradle.org/distributions/gradle-3.4.1-bin.zip
sudo unzip -d /opt/gradle gradle-3.4.1-bin.zip
echo "Gradle is installed at opt gradle #gradle"
cat > set-vars1.sh
export M2_HOME=/usr/local/apache-maven/apache-maven-3.2.2
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
export PATH=$PATH:/opt/gradle/gradle-3.4.1/bin
eval $(./set-vars1.sh)
I am unable to exit the script and unable to export the variables. How do I exit and run the script?
What I am trying to do is create an AMI instance with a packer for which I am writing the above script as a provisioner. I am able to download and unzip maven and gradle but the env variables are not getting exported.
So basically I want to set variables in an instance at runtime.
cat << EOF > set-vars1.sh
export M2_HOME=/usr/local/apache-maven/apache-maven-3.2.2
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
export PATH=$PATH:/opt/gradle/gradle-3.4.1/bin
EOF
You are unable to quit the script because cat > set-vars1.sh is expecting data from the standard input stream. As long as you don't provide that input at the command line and follow it with an EOF (control-D), nothing will happen.
Subsequent export commands are not executed, since the script stays sticked at the cat command above.

error when switching to directory: "perl version 5.12.3 can't run /usr/bin/shasum"

I installed rvm 1.9.3 and now whenever I switch to a directory containing a .rvmrc, I get a perl error message:
~/example$ cd .. && cd example
perl version 5.12.3 can't run /usr/bin/shasum. Try the alternative(s):
/usr/bin/shasum5.10.0 (uses perl 5.10.0)
Run "man perl" for more information about multiple version support in
Mac OS X.
You may try this dirty approach. This approach will skip those check and directly use shasum in your binary directory
$ cd /usr/bin
$ ls shasum*
shasum shasum5.10.0
$ mv /usr/bin/shasum /usr/bin/your_backup_shasum
$ ln -s shasum5.10.0 shasum

Resources