61

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

codeforester
  • 28,846
  • 11
  • 78
  • 104
Amerrnath
  • 1,728
  • 2
  • 17
  • 32

7 Answers7

113

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

sudoz
  • 2,241
  • 1
  • 17
  • 16
  • 8
    This doesn't explain why `shopt` worked in bach (because that it's not a bash built-in). @Omnipresence's answer is more informative. – Jorge Orpinel Jul 12 '16 at 06:45
  • You don't need to `source .zshrc` since it is loaded automatically with `zsh`. – M A Hossain Tonu Oct 17 '19 at 09:45
  • Yes, but if you wanna load the new config immediately under current context, you need refresh it. – sudoz Oct 18 '19 at 07:18
  • The output of my `echo $SHELL` is `/bin/zsh`, my `.zshrc` is in place. All of `.bashrc`, `.bash_profile`, `/etc/profile/` & `/etc/bashrc` r completely commented out. Defaul shell is `zsh`, macOS is latest (Catalina 10.15.4) but I am still facing this exact problem whenever I run any `pyenv` command. I tried changing default shell to `bash` and same problem occured there too. Does this mean my OS is corrupted? [Original Question](https://stackoverflow.com/questions/61478739/pyenv-giving-shopt-command-not-found-error-on-macos) – saadi Apr 29 '20 at 13:07
  • @saadi add the path of `pyenv` to .zshrc file. – sudoz Apr 30 '20 at 05:11
  • @sudoz as I have updated [here](https://stackoverflow.com/q/61478739/10190191), I already have added the path. `penv` is at `/usr/local/bin/` and that directory is already added in path that's why I am not getting `pyenv` command not found, instead, `shopt` command not found. – saadi Apr 30 '20 at 07:28
51

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

Community
  • 1
  • 1
Taimoor Changaiz
  • 8,250
  • 3
  • 45
  • 50
32

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.

Omnipresence
  • 516
  • 3
  • 4
  • can you help me how to use setopt for this shopt – Amerrnath Oct 28 '14 at 18:54
  • 1
    That's not a simple request. Your .bashrc file has at least 109 lines, and I don't know how many of them are comments or whitespace. I can only suggest that you look through your .bashrc file to figure out what it's doing, then find out how to do the same thing in zsh. If you've never customized your `.bashrc`, then maybe all you need it to change your command to: `echo "export NODE_PATH=$NODE_PATH:/usr/local/lib/node_modules" >> ~/.zshrc && source ~/.zshrc` – Omnipresence Oct 28 '14 at 19:36
  • This is the actual answer to the question! Thank you! – mblakesley Mar 22 '21 at 23:43
9

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.

Etan Reisner
  • 68,917
  • 7
  • 78
  • 118
  • echo "export NODE_PATH=$NODE_PATH:/usr/local/lib/node_modules" >> ~/.bashrc && source ~/.bashrc. When i execute this command in my shell i get this error – Amerrnath Oct 28 '14 at 18:45
  • @user1475089 Yes, because your `.bashrc` file contains things that aren't legal `zsh`. You need to stop doing that. If you want that export in your `zsh` shell you stick that in your `zsh` init file and not `.bashrc`. – Etan Reisner Oct 28 '14 at 18:46
  • can explain you me in bit detail – Amerrnath Oct 28 '14 at 18:51
  • 2
    @user1475089 You are trying to use `bash` built-in functionality in `zsh`. That works only marginally worse than trying to use a fork to eat soup. You need to stop using a fork to eat your soup and start learning how to use a spoon. (Go read up about `zsh` and how to do the things you want with it... or stop using `zsh` and go back to using `bash.) – Etan Reisner Oct 28 '14 at 19:03
9

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
Meredith
  • 2,617
  • 3
  • 26
  • 55
Florian
  • 91
  • 1
  • 1
3

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
hxysayhi
  • 1,431
  • 13
  • 22
0

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

  • Found this after searching for a reason why I didn't get history and cmd completion in terminal through few steps. HISTFILE -sh: history: not found was one of them. It apeard after adding user to Ubuntu server. I hope this line helps others find it quicker... – novski Dec 20 '20 at 06:19