shopt command not found in .bashrc after shell updation
Asked Answered
S

8

111

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

Soulsearching answered 28/10, 2014 at 18:38 Comment(7)
zsh is not bash. Why would you source .bashrc?Anthropology
Your bashrc file was written for bash. zsh is not bash. I'm surprised it is trying to load your .bashrc at all. If it isn't and you are sourcing it manually from .profile or similar. Stop. Then replace it with an appropriate zsh init file.Virile
post that as an answerFlunk
can you tell me the source of this errorSoulsearching
I just wannted to add export a path and source a bash . but when i execute it shows this errorSoulsearching
No, you don't want to source ~/.bashrc. You want to figure out how to write a ~/.zshrc file that does the same thing in zsh that .bashrc does in bash.Oeflein
If you want to switch to bash you can execute bash and then execute ~/.bashrcKrimmer
F
181

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

Fad answered 7/9, 2015 at 15:2 Comment(6)
This doesn't explain why shopt worked in bach (because that it's not a bash built-in). @Omnipresence's answer is more informative.Kristykristyn
You don't need to source .zshrc since it is loaded automatically with zsh.Austen
Yes, but if you wanna load the new config immediately under current context, you need refresh it.Fad
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 QuestionImpious
@Impious add the path of pyenv to .zshrc file.Fad
@Fad as I have updated here, 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.Impious
T
85

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

Thirtytwo answered 18/2, 2016 at 7:17 Comment(7)
This should be the accepted answer according to me since some of the settings are being handled by the software installing and not me personallyTaxis
Thank you for a time saver :)Camelliacamelopard
Can I just switch by using bash keyword?Gooey
I mentioned exec bash above to switch to bash. But if only using bash works then it is okThirtytwo
Excelent @TaimoorChangaiz. Thanks!Tush
If all we need is to run bash sometimes, this solution will be the best.Prasad
Ohh my god. This answer saved me from thousands of problems thanks for posting :)Campobello
S
68

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.

Sulphur answered 28/10, 2014 at 18:45 Comment(3)
can you help me how to use setopt for this shoptSoulsearching
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 ~/.zshrcSulphur
This is the actual answer to the question! Thank you!Sinegold
T
25

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
Taeniacide answered 5/3, 2019 at 16:50 Comment(0)
V
12

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.

Virile answered 28/10, 2014 at 18:45 Comment(4)
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 errorSoulsearching
@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.Virile
can explain you me in bit detailSoulsearching
@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.)Virile
E
6

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
Evante answered 17/4, 2019 at 7:58 Comment(0)
S
2

Most of the time will be that your are trying to execute a bash command within the zsh shell

swich to bash with exec bash or

bash

Then go ahead and type source .bashrc

Sigil answered 10/3, 2023 at 11:43 Comment(0)
G
1

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

Georginageorgine answered 23/6, 2018 at 16:15 Comment(1)
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...Maisey

© 2022 - 2024 — McMap. All rights reserved.