How to fix the invalid identifier of bash? - bash

When I open terminal, I get following error at the top.
bash: export: `/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/bin/X11:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/root/bin': not a valid identifier
I am new to linux and I was trying to execute ls command but it was not working and giving some error so I followed this answer to fix it. Now I am able to list down the file using ls command but getting this error. I wonder it will have some serious affect somewhere else or not.

Turns out my path in ~/.bashrc was not correct. So this is what I did.
gedit ~/.bashrc
After the in the opened file I update the PATH to this at the end of the file.
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"

Related

Command not found when opening terminal, possible conda issue?

for some reason whenever I open my terminal it immediately prints the following (after the "last login" line of course):
(eval):116: command not found: dirname
(eval):116: command not found: dirname
__add_sys_prefix_to_path:6: command not found: dirname
__add_sys_prefix_to_path:7: command not found: dirname
It appears that terminal still works fine, but I can't seem to figure out what the cause of these errors could be. The only thing I've "changed" in my terminal last time I used it was setting up a conda environment and installing some new packages.
Any ideas?
You have tampered with the PATH variable and your current PATH cannot figure out where your common utilities are located.
try:
PATH=/bin:/usr/bin:/usr/local/bin:${PATH}
export PATH
Fix the last entry you made in your bash_profile or zshrc file before you started encountering the error.

Why when I open terminal do I see the following:

Last login: Mon Jun 17 10:41:49 on ttys000
-bash: export: `2019.03': not a valid identifier
XXX:~ YYY$
(Note the XXXs and YYYs are just replacement)
Specifically, I am talking about the
-bash: export: `2019.03': not a valid identifier
I just installed Anaconda on Mac and then tried to update it and did in it incorrectly and now when I open the terminal, this appears every time. I know that 2019.03 is the current version of Anaconda and I have since fixed Anaconda so that my version is currently that version but I do not know what this "not a valid identifier" this is. Any help with how to address what it is, why it is there, and how I can remove it would be much appreciated.
EDIT: Thanks for assistance. I opened the bash profile and some of the comments was in the same line as the export path line and that was messing it up. Thank you!
If you open the terminal and see that there is some error coming from ~bash, it likely has something to do with the bash profile. You should open that up and check to make sure that nothing is out of place like having more than one thing on the same line since it can be sensitive to that.
You see the following due to the anaconda3 2019.03 installer trying to export a non valid identifier from your .bash_profile file. Note, this file is usually hidden due to the period in front of the file name.
The following is what was appearing in my terminal:
-bash: export: `2019.03': not a valid identifier
Do the following to fix this issue.
$ nano .bash_profile
Now you should be inside of the .bash_profile file using the nano editor.
# comment out or remove the following line from .bash_profile
# then save before you exit the file
#export PATH="MAMP_PHP:$PATH"# added by Anaconda3 2019.03 installer
Close your terminal and open it again, and the annoying "-bash: export: `2019.03': not a valid identifier" should be gone whenever you open a new terminal.

How to edit corrupted bash profile

I exported a PATH that is incorrect in my bash profile, and I can no longer open it to edit it. Even worse, my terminal is basically completely broken because of this.
If I run vim ~/.bash_profile
I get the following errors:
-bash: vim: command not found
-bash: sed: command not found
If I try to use a command like ls I get:
-bash: ls: command not found
-bash: sed: command not found
How can I fix my bash profile if I can't even edit it?
Your terminal isn't broken, bash is just lost because it is using this broken PATH variable, which you have saved in ~/.bash_profile. So, when you reload (source) your configuration, bash is simply re-reading from the same broken PATH.
To fix it, you must either edit the configuration or replace the file.
In the meantime, you can restore (what is likely) your default PATH temporarily, for the current shell session, from the command-line: PATH="/bin:/sbin:/usr/local/bin:/usr/bin:/usr/sbin:"
Otherwise, you must include the full path to each command you enter (as commented above) since bash no longer knows which directories to look in for these programs (commands).
Try /usr/bin/vim ~/.bash_profile to open the file for editing.
If you'd like to instead remove the file, try: /bin/rm ~/.bash_profile But don't forget to replace it!
Once you've successfully, edited or replaced the file, you need to source it for it to be loaded with each new instance of bash: . ~/.bash_profile.
Also, it is better to place your configuration in the ~/.bashrc file, though this would not have prevented the same situation from happening.

mac terminal blowup: unexpected EOF errors

I've used virtualenv to program using my mac terminal for about 1/2 a year w/no issues. Suddenly today I began to get relative path errors when I tried to load python. There was no apparent reason for it, and eventually I tried restarting my computer.
Then I opened a new terminal window, and these new errors were present for the first time:
-bash: eval: line 4: unexpected EOF while looking for matching `"'
-bash: eval: line 5: syntax error: unexpected end of file
I assume the two misbehaviors are related in some way. Any idea what would be causing it? What files could the terminal be looking at that would cause this? AFIAK, I haven't changed anything on which it would depend.
Thx for any advice!
My guess is that a bash startup file (~/.bashrc, or possibly /etc/profile, ~/.bash_profile, ~/.bash_login or ~/.profile) contains a syntax error, and that causes all sorts of errors for other programs because the setup of the environment they expect does not take place.
From the error message it seems like an unterminated string constant, i.e. a missing ".
The bash manual on startup files has information about this.
You can also try to start bash in debug mode (bash -x (interactive shell) or bash -lx ( login shell)) to try to identify the error.

How to get Terminal on OSX to start up clearly?

I am new to Mac OSX. Once after i typed export command in terminal, each time i start up the terminal, two messages show up:
-bash: export: '=': not a valid identifier
-bash: export: `:/Users/Li/File/Java/TStream': not a valid identifier
I know that clear and command+k can got a clean screen. But I just want to start up with a clean terminal.
Go to your terminal and type the
clear
command. This should clear your screen. Maybe what you're looking for is a way to have bash run that each time. If so, cd to your home directory:
cd ~
then edit the file called .bash_profile , or maybe .bashrc
On the last line write the word 'clear' without quotes, then save. This file runs when bash starts up, and the last thing it will do, therefore, is clear the screen.
For more info, checkout: this
EDIT:
Incidentally, I just realized you might want to clear the error. When you open up your .bashrc file, see if you can find a line that resembles the error you're getting, then comment it out.

Resources