bash file in mac not functioning properly. How to restart or remove it? It is preventing me from doing anything meaningful in Terminal

Solution 1:

In one of your startup scripts you probably have

export PATH= /Users/vishveshbhat/Desktop/flutter/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:$PATH

This sets the PATH variable to an empty string and causes the first error. The culprit is the space character next to =.

Then, in the same or another script that also gets sourced, you probably have

export PATH = /Users/vishveshbhat/Desktop/flutter/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:$PATH

or maybe:

export $PATH= /Users/vishveshbhat/Desktop/flutter/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:$PATH

or something similar. This causes the second and the third error (note $PATH now resolves to nothing). The right general syntax is like

export var=value
# or with many variables at once
export var1=value1 var2=value2 var3="value3 with spaces maybe"

So in your case:

export PATH="/Users/vishveshbhat/Desktop/flutter/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:$PATH"

where

  • there is no space next to =;
  • the variable name (just after export) is not preceded by $.

To fix this you need to temporarily fix your PATH:

PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin

Then in this particular console you should be able to call vi, nano or whatever editor you use and fix the script(s). Files to check:

~/.bashrc
~/.bash_profile
~/.bash_login
~/.profile
/etc/profile
/etc/bash.bashrc

(some of them may not exist, this is normal). If any of them sources another script, check it as well.

It's possible that two separate lines are invalid and each tries to add /Users/vishveshbhat/Desktop/flutter/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin to the beginning of your $PATH. If you fix this, the string will be added twice, which will probably cause no harm, but it's excessive and inelegant. Check carefully. Keep in mind some startup scripts are loaded in some circumstances, others in other.