You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

(eval):1: parse error near `(' when opening the terminal after switching to ZSH

2 years ago, I finally updated my 2018 MacBook pro to macOS Catalina. When I did this, I also switched the default shell on my mac to ZSH. One day, I decided to change my .zshrc file to just say "sudo shutdown -r now". After figuring out that made my mac shut down when I opened the terminal, I quickly changed it tack to the original. However, when I upgraded to macOS Monterey, it started to give me this error: (eval):1: parse error near `(' . I don't know why this happened but it is extreamly annoying. I have attatched an image of the problem. Some info like my name is blanked out. If anyone knows a fix to this, it would be extreamly helpful. Thanks.

MacBook Pro 13″, macOS 12.0

Posted on Mar 20, 2022 4:41 PM

Reply
Question marked as Top-ranking reply

Posted on Mar 20, 2022 6:30 PM

If you have a backup, then try restoring the file from a backup made before you made the original change to include the "shutdown" command. The file is now damaged as you likely deleted something from another line in the file, or perhaps you used a GUI text editor that did not save the file as pure text. It is a good idea to make sure you backup a file before you make changes to it so you can easily restore the file if a mistake is made.


The easiest way is probably to create a new macOS user account, then copy that file from the new macOS user account to your main macOS user account to overwrite the currently broken file. You will need to change the permissions of this file so it works with your main user account. Check the permissions of the current file now before you overwrite it with the good default file. Of course if any apps have modified this file, then you will lose those modifications, so some apps may not work correctly.


You need to make sure the Terminal app is closed before replacing that zsh profile.


Otherwise you would have to boot into Single User Mode or Recovery Mode and fix the broken file. I think repairing the file is beyond your current knowledge of the command line if you blindly used the "shutdown" command within the file in the first place. I don't mean any disrespect here as it is just an observation. We all start out with no knowledge of the command line and we have all made mistakes learning how to use the command line. Plus with macOS 10.15+, it is much more difficult to provide instructions on how to access files since macOS now contains multiple APFS volumes.


Most macOS users should never need to use the command line. If a user wants or needs to use the command line, then extreme care must be taken since the command line offers no protection or training wheels. Even expert users with decades of command line experience can easily make a critical mistake and destroy critical system files or even their data by something as simple as a typographical error. Never blindly use any command. Make sure you learn about the command and have a basic understanding of the command before executing the unknown command. In fact I would recommend learning the command line using an older Mac where a mistake won't cause any harm to your data and where a clean install will not disrupt your work on the main computer if a mistake is made which is not easily fixed.


If you are unfamiliar with a command, then usually you can read the manual page for that command to understand how it operates. For example, to read the manual for the "shutdown" command you would type the following:

man  shutdown


There are a lot of online resources providing information about the command line. The majority of those resources will be for Linux and the Bash shell, but the general concepts apply to macOS as well although the macOS versions of the command line utilities are very old and outdated (at least regarding Bash) so with the online Linux resources you will find commands with lots of options which are not available on macOS.

Execute commands and run tools in Terminal on Mac - Apple Support


https://www.davidbaumgold.com/tutorials/command-line/


zsh specifics:

https:https://ryanstutorials.net/linuxtutorial/


Here is an article about Linux Bash, but it is well written with lots of examples which can generally be applied to macOS as well (for any zsh specific information you will need to search online for "zsh"):

https://ryanstutorials.net/linuxtutorial/


Hope this helps to get you started. I rarely look at or modify the shell preference files (especially on macOS) so I cannot give you any more specifics. I also have never used anything "zsh" specific as all my experience has been with Bash.


You should always have frequent and regular backups of your computer and all external media which contains important & unique data.



Similar questions

14 replies
Question marked as Top-ranking reply

Mar 20, 2022 6:30 PM in response to qwertyuiopm

If you have a backup, then try restoring the file from a backup made before you made the original change to include the "shutdown" command. The file is now damaged as you likely deleted something from another line in the file, or perhaps you used a GUI text editor that did not save the file as pure text. It is a good idea to make sure you backup a file before you make changes to it so you can easily restore the file if a mistake is made.


The easiest way is probably to create a new macOS user account, then copy that file from the new macOS user account to your main macOS user account to overwrite the currently broken file. You will need to change the permissions of this file so it works with your main user account. Check the permissions of the current file now before you overwrite it with the good default file. Of course if any apps have modified this file, then you will lose those modifications, so some apps may not work correctly.


You need to make sure the Terminal app is closed before replacing that zsh profile.


Otherwise you would have to boot into Single User Mode or Recovery Mode and fix the broken file. I think repairing the file is beyond your current knowledge of the command line if you blindly used the "shutdown" command within the file in the first place. I don't mean any disrespect here as it is just an observation. We all start out with no knowledge of the command line and we have all made mistakes learning how to use the command line. Plus with macOS 10.15+, it is much more difficult to provide instructions on how to access files since macOS now contains multiple APFS volumes.


Most macOS users should never need to use the command line. If a user wants or needs to use the command line, then extreme care must be taken since the command line offers no protection or training wheels. Even expert users with decades of command line experience can easily make a critical mistake and destroy critical system files or even their data by something as simple as a typographical error. Never blindly use any command. Make sure you learn about the command and have a basic understanding of the command before executing the unknown command. In fact I would recommend learning the command line using an older Mac where a mistake won't cause any harm to your data and where a clean install will not disrupt your work on the main computer if a mistake is made which is not easily fixed.


If you are unfamiliar with a command, then usually you can read the manual page for that command to understand how it operates. For example, to read the manual for the "shutdown" command you would type the following:

man  shutdown


There are a lot of online resources providing information about the command line. The majority of those resources will be for Linux and the Bash shell, but the general concepts apply to macOS as well although the macOS versions of the command line utilities are very old and outdated (at least regarding Bash) so with the online Linux resources you will find commands with lots of options which are not available on macOS.

Execute commands and run tools in Terminal on Mac - Apple Support


https://www.davidbaumgold.com/tutorials/command-line/


zsh specifics:

https:https://ryanstutorials.net/linuxtutorial/


Here is an article about Linux Bash, but it is well written with lots of examples which can generally be applied to macOS as well (for any zsh specific information you will need to search online for "zsh"):

https://ryanstutorials.net/linuxtutorial/


Hope this helps to get you started. I rarely look at or modify the shell preference files (especially on macOS) so I cannot give you any more specifics. I also have never used anything "zsh" specific as all my experience has been with Bash.


You should always have frequent and regular backups of your computer and all external media which contains important & unique data.



Mar 27, 2022 8:38 AM in response to HWTech

The error actually also happened before I edited the .zshrc file. And I also made the change when I had little knowledge of shell scripting. After I realized that I messed up big time, I ran another command that replaced my .zshrc file with another file from oh my zsh. Also, this error only happens when I open the terminal in VScode.

Mar 27, 2022 8:50 AM in response to qwertyuiopm

I also found my .zshrc file.


# System-wide profile for interactive zsh(1) shells.


# Setup user specific overrides for this in ~/.zshrc. See zshbuiltins(1)

# and zshoptions(1) for more details.


# Correctly display UTF-8 with combining characters.

if [[ "$(locale LC_CTYPE)" == "UTF-8" ]]; then

setopt COMBINING_CHARS

fi


# Disable the log builtin, so we don't conflict with /usr/bin/log

disable log


# Save command history

HISTFILE=${ZDOTDIR:-$HOME}/.zsh_history

HISTSIZE=2000

SAVEHIST=1000


# Beep on error

setopt BEEP


# Use keycodes (generated via zkbd) if present, otherwise fallback on

# values from terminfo

if [[ -r ${ZDOTDIR:-$HOME}/.zkbd/${TERM}-${VENDOR} ]] ; then

source ${ZDOTDIR:-$HOME}/.zkbd/${TERM}-${VENDOR}

else

typeset -g -A key


[[ -n "$terminfo[kf1]" ]] && key[F1]=$terminfo[kf1]

[[ -n "$terminfo[kf2]" ]] && key[F2]=$terminfo[kf2]

[[ -n "$terminfo[kf3]" ]] && key[F3]=$terminfo[kf3]

[[ -n "$terminfo[kf4]" ]] && key[F4]=$terminfo[kf4]

[[ -n "$terminfo[kf5]" ]] && key[F5]=$terminfo[kf5]

[[ -n "$terminfo[kf6]" ]] && key[F6]=$terminfo[kf6]

[[ -n "$terminfo[kf7]" ]] && key[F7]=$terminfo[kf7]

[[ -n "$terminfo[kf8]" ]] && key[F8]=$terminfo[kf8]

[[ -n "$terminfo[kf9]" ]] && key[F9]=$terminfo[kf9]

[[ -n "$terminfo[kf10]" ]] && key[F10]=$terminfo[kf10]

[[ -n "$terminfo[kf11]" ]] && key[F11]=$terminfo[kf11]

[[ -n "$terminfo[kf12]" ]] && key[F12]=$terminfo[kf12]

[[ -n "$terminfo[kf13]" ]] && key[F13]=$terminfo[kf13]

[[ -n "$terminfo[kf14]" ]] && key[F14]=$terminfo[kf14]

[[ -n "$terminfo[kf15]" ]] && key[F15]=$terminfo[kf15]

[[ -n "$terminfo[kf16]" ]] && key[F16]=$terminfo[kf16]

[[ -n "$terminfo[kf17]" ]] && key[F17]=$terminfo[kf17]

[[ -n "$terminfo[kf18]" ]] && key[F18]=$terminfo[kf18]

[[ -n "$terminfo[kf19]" ]] && key[F19]=$terminfo[kf19]

[[ -n "$terminfo[kf20]" ]] && key[F20]=$terminfo[kf20]

[[ -n "$terminfo[kbs]" ]] && key[Backspace]=$terminfo[kbs]

[[ -n "$terminfo[kich1]" ]] && key[Insert]=$terminfo[kich1]

[[ -n "$terminfo[kdch1]" ]] && key[Delete]=$terminfo[kdch1]

[[ -n "$terminfo[khome]" ]] && key[Home]=$terminfo[khome]

[[ -n "$terminfo[kend]" ]] && key[End]=$terminfo[kend]

[[ -n "$terminfo[kpp]" ]] && key[PageUp]=$terminfo[kpp]

[[ -n "$terminfo[knp]" ]] && key[PageDown]=$terminfo[knp]

[[ -n "$terminfo[kcuu1]" ]] && key[Up]=$terminfo[kcuu1]

[[ -n "$terminfo[kcub1]" ]] && key[Left]=$terminfo[kcub1]

[[ -n "$terminfo[kcud1]" ]] && key[Down]=$terminfo[kcud1]

[[ -n "$terminfo[kcuf1]" ]] && key[Right]=$terminfo[kcuf1]

fi


# Default key bindings

[[ -n ${key[Delete]} ]] && bindkey "${key[Delete]}" delete-char

[[ -n ${key[Home]} ]] && bindkey "${key[Home]}" beginning-of-line

[[ -n ${key[End]} ]] && bindkey "${key[End]}" end-of-line

[[ -n ${key[Up]} ]] && bindkey "${key[Up]}" up-line-or-search

[[ -n ${key[Down]} ]] && bindkey "${key[Down]}" down-line-or-search


# Default prompt

PS1="%n@%m %1~ %# "


# Useful support for interacting with Terminal.app or other terminal programs

[ -r "/etc/zshrc_$TERM_PROGRAM" ] && . "/etc/zshrc_$TERM_PROGRAM"

Mar 27, 2022 8:57 AM in response to qwertyuiopm

Would need to see the contents of your .zshrc file. However, one thing to make sure of is that you do not have a line like this in your .zshrc file:


source ~/.bash_profile


Because that would definitely cause the precise error you are seeing. The source command loads another configuration file while running the existing configuration file. Bash is not entirely compatible with Zsh, there are subtle differences in the configuration files. Zsh can run bash scripts but not the configuration files. You'll need to duplicate the settings in .bash_profile or .bashrc if you are attempting to source them in your .zshrc.



Mar 27, 2022 10:16 AM in response to James Brickley

James Brickley wrote:

Try using "open .zshrc" and it should open in TextEdit then copy / paste in reply. If it's too big, use the Additional Text button.

It would be better to paste it into the "Code Insertion" tool feature as it makes code much more readable as it uses a more readable font. The "Code Insertion" Tool has the icon which looks like "<>" on the forum editing window toolbar.


Mar 27, 2022 3:30 PM in response to qwertyuiopm

In Terminal preferences for the default profile, under the Shell tab. Are you running anything? Try a different Terminal profile. If a different Terminal profile doesn't have the problem look at the list of profiles in Terminal, there's an ellipsis button with a down arrow next to the plus and minus buttons at the bottom of the list. Drop down the list and Restore Default Profiles. Make the Basic on your default. Restart Terminal.



(eval):1: parse error near `(' when opening the terminal after switching to ZSH

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.