Ubuntu 19.10 .. can't change shell to zsh - shell

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?

Related

installing oh-my-zsh for a different user as root in cloud-init script

I'm attempting to bootstrap my AWS EC2 ubuntu server with oh-my-zsh installed for the ubuntu user. I have a cloud-init script (more info here) that runs as the root user (with sudo). So, in my script I run the oh-my-zsh installation as the ubuntu user.
#cloud-config
runcmd:
# omitted other commands specific to my server, install zsh at the end
- apt-get install -y zsh
- su ubuntu -c 'sh -c "$(curl -fsSL https://raw.githubusercontent.com/coreycole/oh-my-zsh/master/tools/install.sh)"'
- chsh -s $(which zsh) ubuntu
# change the prompt to include the server hostname
- su ubuntu -c echo "echo export PROMPT=\''%{$fg[green]%}%n#%{$fg[green]%}%m%{$reset_color%} ${ret_status} %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)'\'" >> /home/ubuntu/.zshrc
# get environment variables defined above
- echo "source ~/.profile" >> /home/ubuntu/.zshrc
When the cloud-init finishes and I ssh into the colors are not working in the $PROMPT, I see [green] and [cyan]:
[green]ubuntu#[green]ip-172-31-27-24 [cyan]~
If I run the same PROMPT command as the ubuntu user after ssh'ing in, the colors work correctly:
The problem seems to be how the colors are evaulated when the cloud-init script runs the echo command vs how the colors are evaulated when the ubuntu user runs the echo command. Does anyone know how I might change the PROMPT so the colors are only evaulated once ~/.zshrc is evaulated by the ubuntu user?
I solved this thanks to jgshawkey's answer here. I used bash variables to escape the color codes & commands to postpone their evaluation:
- apt-get install -y zsh
- runuser -l ubuntu -c 'sh -c "$(curl -fsSL https://raw.githubusercontent.com/coreycole/oh-my-zsh/master/tools/install.sh)"'
- chsh -s $(which zsh) ubuntu
- fgGreen='%{$fg[green]%}'
- fgCyan='%{$fg[cyan]%}'
- fgReset='%{$reset_color%}'
- retStatus='${ret_status}'
- gitInfo='$(git_prompt_info)'
- runuser -l ubuntu -c "echo export PROMPT=\''${fgGreen}%n#%m${fgReset} ${retStatus} ${fgCyan}%c${fgReset} ${gitInfo}'\'" >> /home/ubuntu/.zshrc
- echo "source ~/.profile" >> /home/ubuntu/.zshrc
It ended up looking like this in my ~/.zshrc:
Since I am creating a new user/server, I made this way:
user=you user here
pass=you password here
apt install -y zsh curl wget # considering you currently are root
#creates a new user with password and zsh as default shell
useradd "$user" -m -p $(openssl passwd -1 "$pass") -s $(which zsh)
usermod -aG sudo "$user" # append to sudo and user group (optional)
# mind the command above, with the parameter --unattended which means "no questions" and "no set default to zsh"
runuser -l $user -c 'sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended'
Worked fine for me.

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)

'scl enable' not setting PATH with 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!

Running script with ssh

I work with machine A and I want to run a script that exists in machine B.
I did the ordinary command:
ssh user#machine_B_adress '. script.sh'
the problem is that I used in the script some commands that cannot be interpret with machine A. So I get command not found: (for example)
ksh: sqlplus: not found
I tried to open a shh by:
ssh user#machine_B_adress
and then run the script, it works!!!
Assuming that the shell for user#machine_B is bash, the first example 'ssh user#machine_B_adress '. script.sh', bash sets up the shell env differently for interactive/non-interactive sessions.
See man bash about interactive shells
Looks like you can emulate the interactive environment by adding a bash -l -c
$ ssh user#machine_B_address "bash -l -c '. script.sh'
My quick test, I added debug echo to .bash_profile of the remote user
$ ssh foouser#jdsrpi1 "bash --login -c '. foo.sh'"
This is file .bash_profile
foouser
SHELL = /bin/bash
PATH = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
Similar scenario for ksh
$ ssh kshuser#jdsdrop1.jimsander.io "date"
Tue Apr 18 11:52:43 EDT 2017
$ ssh kshuser#jdsdrop1 "ksh -l -c date"
This is SHELL(/usr/bin/ksh) file .profile
Tue Apr 18 11:53:24 EDT 2017

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