Accidentally cleared ~/.bash_profile contents (Mac) [duplicate] - macos

This question already has an answer here:
How to restore .bash_profile on a mac? None of my unix terminal are working [closed]
(1 answer)
Closed 3 years ago.
I accidentally used > to put an output inside ~/.bash_profile and ended up erasing a lot of configs I had saved there.
I need help to recover it. I still have iTerm opened with all the ~/.bash_profile old settings before erase active. Which means next time I close it or do source ~/.bash_profile all the settings will be lost forever.
Is there a way to recover the current ~/.bash_profile settings loaded? Or something?

Normally, .bashrc is a copy from /etc/skel, so you can restore it from there.
If you added some extra informations in this file, you still have them available in your current session. To recover those, say:
env to see those variables.
typeset -f to see the functions that are defined.

Related

bash alias disappears when opening new terminal [duplicate]

This question already has answers here:
Should aliases go in .bashrc or .bash_profile? [duplicate]
(4 answers)
Closed 4 years ago.
im setting up a new alias by typing this command:
vi ~/.bashrc
and then placing my alias:
alias school='ssh -Y username#linux.student.cs.uwaterloo.ca'
followed by exiting the file using: wq
however when i close my terminal and open my terminal, i get a "command can't be found." error message.
if i type source ~/.bash_aliases, it will work, the alias will work, but when i open a new terminal it won't.
is my .bashrc supposed to be empty when i vi into it?
The reason your alias is getting lost is because you dont have your bashrc sourced in a new terminal.
Same will happen even if you create a new alias file and source it in bashrc because its scope gets limited to the terminal you are editing in.
What you can do is logout once and then log in back so that bashrc entries gets updated for your user account or you can source in each terminal by typing
source ~/.bashrc
By adding the same entry to '''.profile''' you are making sure the alias is set on each system boot.
So its better to set the alias in .bashrc rather than .profile
Another major point to nite here is to make sure you dont delete anything in bashrc since that will do catastrophic changes to you session.

Bash issue when open terminal [duplicate]

This question already has an answer here:
How to restore .bash_profile on a mac? None of my unix terminal are working [closed]
(1 answer)
Closed 2 years ago.
I receive this error message each time I launch terminal:
-bash: =/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin: No such file or directory
You have recently edited one of your shell's startup files and introduced an error.
Probably, ls -lart ~/.bashrc ~/.bash_profile ~/.profile will indicate which one -- if one or more is missing, that's no concern, we just want to see which one out of these you have edited recently. Examine the time stamps and try to remember what you did to change one of these files.
The error probably looks something like
$oopsPATH=/usr/local/bin:$PATH
where you meant to say
PATH=/usr/local/bin:$PATH
but without access to your files, we can't know what exactly is supposed to be there, or how you messed it up.
See also https://askubuntu.com/questions/198730/how-to-restore-bashrc-file/198740#198740
In the common case where you have messed up your PATH so that ls and other commands are unavailable (bash: ls: command not found), you can use the full path (/bin/ls pro ls, etc; though obviously, you have to know the correct path) at least until you can restore your configuration.
PATH=/usr/local/bin:/usr/bin:/bin
is probably a good crutch until you can find the correct default for your OS. You can type that at the prompt, or put it in one of your shell's startup files and start a new shell.
On many platforms, you can find the default user dot files in /etc/skel so if that's present (which unfortunately will not be true for Mac OS, but should be there on most Linuxes):
cp -b /etc/skel/.bash_profile $HOME/
will replace your (presumably broken beyond repair) .bash_profile with the system default one. (Omit the -b option if your OS doesn't have it, but then you'll want to back up your file manually before replacing it.)
Update: This fragment near the top of your .bash_profile is erroneous:
#loginPath
=/usr/local/bin:$PATH
Just take it out; it doesn't seem to do anything useful. There seem to be multiple additional fragments from the MacPorts installer which look wrong, too, but they are just comments. (Perhaps somehow they shouldn't be?)
It seems that you are missing a necessary PATH and that is why it is saying no such file or directory. If, for example, you get this error message when typing in python, it would mean either that (1) python isn't installed; or (2) python isn't on your system path.

Mac Yosemite, tried to change my bash profile path, but I messed up and now terminal cant find any commands [duplicate]

This question already has an answer here:
How to restore .bash_profile on a mac? None of my unix terminal are working [closed]
(1 answer)
Closed 7 years ago.
I tried fixing an unrelated problem by changing my path in my .bash_profile, but I think I messed up and now my terminal cant find any command, not even 'ls' or 'nano'. Is there any way to edit the bash profile file back to the original without using the command line? Is there a way I could find my bash profile in finder and edit it with the text app? Or do I have to factory wipe my MacBook?
okay yeah I fixed it by changing my setting PATH=/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin‌​:/sbin and that gave me the bash commands back and then I could use nano to edit the profile back to how it was before I messed with it. I feel really dumb.

Removing no such file command from OSX terminal startup [duplicate]

This question already has an answer here:
How to restore .bash_profile on a mac? None of my unix terminal are working [closed]
(1 answer)
Closed 8 months ago.
Whenever I start a new Terminal session, the window opens up with a command:
'-bash: cd: /Users/yourusername/Library/lejos_nxj: No such file or directory'.
I want to remove that line from coming up on the prompt, so I deleted the Terminal plist file and sent hard resets, but nothing has worked for me so far.
Is there anything I haven't tried yet?
You've probably got something in your ~/.profile, which is automatically executed when you open a Terminal.
If you did not set anything in there, do
rm ~/.profile
in a Terminal and this should disappear.
If you think that something important may be in there, do
open -a TextEdit ~/.profile
(or change TextEdit to your preferred editor) to view and edit the file.
That line is probably in either your ~/.bashrc file or your ~/.profile file. I would check those two files first (and they are both hidden because of the period initial character).
Edit: I just checked my OS X system, and I don't have ~/.bashrc (but you may).
You could try a terminal replacement (Just recently read about this one, iTerm2) it might
resolve your problem by using its own default startup settings.
If it is anything like Linux the ~/.bashrc and ~/.profile are used when you open your terminal.
It seems that most people assume it is in some init file but its not clear which are included. Once your shell does come up (ignore errors) -try this:
script
bash -l -x
exit
exit
Now you should have a file called typescript which will have debug info showing most if not all of what the shell has executed when coming up in login mode. You could for instance do grep source typescript to see which files were involved OR you could find refrences to nxj etc.
p.s. I assume your clearing of the plist would clear the preferences, but wouldn't hurt to see if the relevant command is in 'Terminal-> Presences->Settings->Shell->Run Command' for any of the terminal window presets

restore PATH under Mac OS X [duplicate]

This question already has an answer here:
How to restore .bash_profile on a mac? None of my unix terminal are working [closed]
(1 answer)
Closed 6 years ago.
Hi guys I tried to add new directory to the PATH, but instead appending I overwrote it. Is there any way to restore those default paths?
If you changed your PATH in a Terminal shell, simply close that Terminal window and open a new one. Changes to environment variables are local to the shell in which you change them (and any subshells created by that one).
Just restart your terminal that will assign variables based on your .profile or .bashrc ( if you are running bash )

Resources