shopt command not found in .bashrc after shell updation

BashShZshrcShopt

Bash Problem Overview


I have updated my shell to ZSH. When I source ~/.bashrc. I am getting this error

There was some error in yo doctor . when i execute this command

echo "export NODE_PATH=$NODE_PATH:/usr/local/lib/node_modules" >> ~/.bashrc && source ~/.bashrc

> /home/amerrnath/.bashrc:17: command not found: shopt > /home/amerrnath/.bashrc:25: command not found: shopt > /home/amerrnath/.bashrc:109: command not found: shopt > /usr/share/bash-completion/bash_completion:35: parse error near `]]'

Please help me resolve this problem

Bash Solutions


Solution 1 - Bash

zsh uses env profile ~/.zshrc, not ~/.bashrc.

so you need to append your env settings to .zshrc file and then

source ~/.zshrc

It must work.

rbenv github link

Solution 2 - Bash

To place anything in ~/.bashrc:

Switch to bash:

exec bash

Then

source ~/.bashrc

Switching to bash will not effect on new terminal window. But if you want to switch current window to zsh.

Switch to zsh:

exec zsh

reference

Solution 3 - Bash

shopt is not a command, but a shell built-in. bash knows what to do with it because it's a bash built-in , but zsh has no idea what it is. You'll want to look into setopt which is a zsh built-in, and put those values into a new .zshrc script.

Solution 4 - Bash

Make an alias of shopt and call it through zsh

A quick solution is described here: https://github.com/larz258/Zshopt

sudo vi /usr/bin/shopt

Inside the shopt

#!/bin/bash
args='';
for item in $@
  do
    args="$args $item";
  done
shopt $args;

make it executable

sudo chmod +x /usr/bin/shopt

Create an alias in your .zshrc

echo "alias shopt='/usr/bin/shopt'" >> ~/.zshrc

Solution 5 - Bash

Your bashrc file was written for bash. zsh is not bash.

I'm surprised zsh is trying to load your .bashrc at all.

If it isn't and you are sourcing it manually (from .profile or similar). Stop doing that.

Then you get to write an appropriate zsh init file instead.

If you want to use zsh then you need to use zsh and not bash.

shopt is a bash-ism.

[[ is a bash-ism.

Solution 6 - Bash

shopt is not a command, but a shell built-in. You can find out this by running the following command in bash:

type shopt

output would be:

shopt is a shell builtin
solution:

step1:

echo "#! /bin/bash\n\nshopt \$*\n" > /usr/local/bin/shopt

then you will get /usr/local/bin/shopt:

#! /bin/bash

shopt $*

step2:

chmod +x /usr/local/bin/shopt

step3:

ln -s /usr/local/bin/shopt /usr/bin/shopt

step4:

echo "alias shopt='/usr/bin/shopt'" >> ~/.zshrc

Solution 7 - Bash

For some reason after the upgrade from 16.04 to 17.10 and to 18.04, the symlink /bin/sh was set back to dash not bash. Updating this link:

sudo cd /bin && ln -sf bash sh

solved this problem for me

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAmerrnathView Question on Stackoverflow
Solution 1 - BashsudozView Answer on Stackoverflow
Solution 2 - BashTaimoor ChangaizView Answer on Stackoverflow
Solution 3 - BashOmnipresenceView Answer on Stackoverflow
Solution 4 - BashFlorianView Answer on Stackoverflow
Solution 5 - BashEtan ReisnerView Answer on Stackoverflow
Solution 6 - BashhxysayhiView Answer on Stackoverflow
Solution 7 - BashAndrei MironenkoView Answer on Stackoverflow