How to get Terminal on OSX to start up clearly? - macos

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.

Related

How to fix the invalid identifier of 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"

-bash: /bin/bash:: No such file or directory

I am on Windows 10v1803, and i have WSL with Ubuntu installed and working well.
Recently, i was in vim, and appending some aliases to my .bashrc. After I finished editing, I wanted to exit without saving, did the usual Control-C, and instead of :q! I did !:q (Yes, silly typos). I realized my mistake, did the correct :q! and exited.
I came back ~1hr later, to make those 2 changes (below) and noticed that on startup, I got the error
-bash: /bin/bash:: No such file or directory
along with the normal startup
suda#suda:~$
Everything proceeds normally, but i'm concerned as to what that error means.
And, there is nothing that I could find on this apart from reinstall bash, which i have done 5 times, and makes no difference.
I proceeded to add the 2 aliases to my .bashrc, and everything works fine...
Some help as to what is happening here please?
And if you're wondering, these were what i was adding onto my .bashrc:
alias cls="clear"
alias md="mkdir"
Also, I feel that this won't go under askubuntu. If i'm wrong, please do tell me.
Edit: Here's an image
The error message is:
-bash: <file>: No such file or directory
Check that your script doesn't start with
#!/bin/bash:
and that you do not invoke /bin/bash: elsewhere, either.
(because, indeed, bash: should not exist in /bin)

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.

-bash: ≈: command not found (OS X Terminal Error), How to Fix?

Whenever I start up Terminal on my Macbook Air, I get this message:
-bash: ≈: command not found
How do I fix this error? I'm running Mavericks version 10.9.4 if that helps at all.
EDIT: Fixed this error by using the bash -x method, found out it was a random '≈' character left in ~/.profile that needed to be deleted. Thanks for the answers :)
To debug you can try this:
bash -x -l
(the -l might not be needed).
I definitely agree with Barmar, there is something in your bash startup scripts.
There is not a great way to do this, but here is the protocol to remedy it.
Confirm it is your bash profile by first killing the process with a control + C if it is hung. Then do a source ~/.bash_profile and see if you get that same error.
Backup your bash profile cp ~/.bash_profile bashprofile.txt
Then comment out part of your bash profile. With text wrangler you can do a command + slash.
Save, then do a source ~/.bash_profile and see if the error still prints.
Repeat with different areas of the script until you have isolated the infected region.

Basic command lines on Mac terminal not working

I changed the bash profile while trying to install mongodb and none of my command lines are working on terminal. I read online that I need to fix the $PATH but I can't even access it when none of my commands are working.
Help?
Mistakenly I also ran into same problem where to resolve this I had to reset my PATH variable to basic settings as below :
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin"
Once you set PATH variable now you can open the .bash_profile file in same terminal session only and make changes accordingly. This will resolve your problem.
Ok I found the answer from here:
"Open Terminal, and go to File (or Shell) -> New Command. Type in open -e .profile (or substitute some other file instead of .profile), and hit Run. That should open TextEdit with the file you want to fix; you can remove the offending lines there."
in my case i typed in nano .bash_profile and that allowed me to edit my bash profile and fix the issue.
can't use terminal from error in .bash_profile
Run this in terminal:
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"

Resources