can't access .bash_profile - bash

So I was adding a path to my bash profile, and I accidentally started it with 'myname 1' instead of 'myname1'. I think the space has messed something up.
When I open my terminal now, I get:
-bash: export: `1/Documents/android-sdk-macosx/platform-tools:/Users/XXXX/Library/PreferencePanes/MMPane.prefPane/Contents/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/mysql/bin': not a valid identifier
-bash: dirname: command not found
-bash: /Users/bin/git-prompt.sh: No such file or directory
I know the '1/ is super messed up, but now when I try to edit the profile again nothing works. I can't access it with nano or anything. I don't even think it can find my profile anymore.
Does anyone know how I can access that old profile to fix the edit I made?

It's likely that your PATH environment variable has now been set to myname, and so trying to run a command foo will now only work if an executable named myname/foo exists. The way around this is to give the absolute path of any program you want to execute. For example, nano most likely resides in your /usr/bin directory, and so you should be able to run it to edit your .bash_profile by typing:
/usr/bin/nano ~/.bash_profile
If that's not the correct path, other likely locations for nano include /usr/local/bin/nano and /usr/pkg/bin/nano; the correct answer depends on your operating system and distribution thereof.

Type the full path to the editor.
I assume the following will work:
/bin/vi .bash_profile

Related

I have accidentally set up my path environment variable incorrectly using the .bash_profile on macbook. How do I reset it?

-bash: export: /Users/deboadebayo/Desktop/Coding/:/opt/anaconda3/bin:/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin':
not a valid identifier
The above message is the error message I receive every time I open my terminal. I did create a backup of my bash profile. But essentially now I can no longer navigate anywhere I want to go using command line requests.
Any help would be much appreciated
If you have a backup, use an absolute path to the mv and cp commands to rename your broken file and restore the backup, both without depending on path lookup.
/bin/mv .bash_profile .bash_profile.broken
/bin/cp .bash_profile.backup .bash_profile
Close the current terminal window and open a new one, which should use your working, original .bash_profile to initialize PATH. Now you try to make the correct modification to your PATH.
oops. The easiest way to fix it would be to launch an editor with an absolute path. $PATH only specifies the locations in which the shell will search if told to execute a program relative (or no) path specified. The which program can search the path and shows the first executable found:
$ which vim
/usr/bin/vim
So if you're a vim user, you should be able to run /usr/bin/vim at the command line, and the path won't be relevant. Then you can fix your file in the editor. Looks like my osx machine also has nano if you'd prefer that editor. I don't think I installed it so it probably came shipped with osx I'm guessing:
$ which nano
/usr/bin/nano
If you want to revert to your backup, use cp, but specify it from its absolute position, /bin/cp:
$ /bin/cp first.txt second.txt
Obviously you'll want to change the file names on that one for it to work for you.

How does my system know to look in a deleted folder for a binary?

If I try to run virtualenv, I get this message:
$ virtualenv
-bash: /Users/me/Library/Python/3.6/bin/virtualenv: No such file or directory
It's not surprising that this happens, because I've removed this directories at an earlier point when trying to clean up my computer from different Python versions. However, how does my system know to look in that directory for virtualenv? I've looked in my bash profile, and there is no mention of virtualenv there.
When you type something your command interpreter has to search the command. Of course it cannot try every possible directory on your system. Then it provides to the user a way to control that process. This is the purpose of the PATH environment variable :
$ echo $PATH
will show you the actual value which looks like dir1:dir2:...:dirn, meaning that commands where searched for in dir1, then dir2, etc. You have to remove the value /Users/me/Library/Python/3.6/bin/ from it. The best way is to edit the .bashrc or .bash_profile file to remove the permanent setting of this variable. Then reconnect.

Cant access my bash files

So I wanted to install MySQL on my MBP and I edited my bash_profile, added a path variable, however when I run echo $PATH from iTerm2 I get my path as:
Robs-MBP:~ Rob$ echo $PATH
/usr/local/mysql/bin
Ive tried a lot of commands and even used sudo and it just says command not found. My fear is that I have completely messed up, and now nothing works. Please help.
You've made a simple mistake: all you've done is reset the PATH env variable. To correctly do this, you should always add the existing PATH to the end of whatever you're adding. In you case:
PATH=/usr/local/mysql/bin:$PATH
To fix your problem from the terminal, you'll need to reset your PATH to somewhere with a text editor. I don't know where this is located on OSX, so you'll have to find it. After you know where your path should point, run:
$ export PATH=<YOUR_PATH_HERE>
Then edit your bashrc to include the original path as described above, and restart the terminal.
Alternatively, open .bashrc with a GUI text editor and make the change from there. Your PATH decleration should always end in :$PATH to include the PATH created by your system.

How to remove entry from $PATH on mac

I was trying to install Sencha Touch SDK tools 2.0.0 but could not run it properly. It created an entry in the $PATH variable.
Later I deleted the sencha sdk tools folder but didn't realize that the path variable is still there.
When i did echo $PATH I got -
/Applications/SenchaSDKTools-2.0.0-beta3:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
I searched on how to remove variables from $PATH and followed these steps :
Gave the command PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin"
Did echo $PATH which showed /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
gave the command export PATH
Closed terminal and reopened it. Gave the command echo $PATH. This time I got
/Applications/SenchaSDKTools-2.0.0-beta3:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
Can anyone tell me what am i doing wrong?
echo $PATH and copy it's value
export PATH=""
export PATH="/path/you/want/to/keep"
Check the following files:
/etc/bashrc
/etc/profile
~/.bashrc
~/.bash_profile
~/.profile
~/.MacOSX/environment.plist
Some of these files may not exist, but they're the most likely ones to contain $PATH definitions.
On MAC OS X Leopard and higher
cd /etc/paths.d
There may be a text file in the above directory that contains the path you are trying to remove.
vim textfile //check and see what is in it when you are done looking type :q
//:q just quits, no saves
If its the one you want to remove do this
rm textfile //remove it, delete it
Here is a link to a site that has more info on it, even though it illustrates 'adding' the path. However, you may gain some insight.
What you're doing is valid for the current session (limited to the terminal that you're working in). You need to persist those changes. Consider adding commands in steps 1-3 above to your ${HOME}/.bashrc.
If you're removing the path for Python 3 specifically, I found it in ~/.zprofile and ~/.zshrc.
$PATH contains data that is referenced from actual files. Ergo, you should find the file containing the reference you want to delete, and then delete said reference.
Here is a good list to run through progressively [copied from #Ansgar's answer with minor updates].
/etc/bashrc
/etc/profile
~/.bashrc
~/.bash_profile
~/.profile
~/.MacOSX/environment.plist
/etc/paths
/etc/paths.d/
Note that /etc/paths.d/ is a directory that contains files with path references. For example, inside this directory may be a file called, say, fancy-app, and inside this file you'll see an entry like below:
/path/to/fancy-app
This path will appear in your $PATH and you can delete the entry in the file to remove it, or you can delete the file if it has only the one reference you want to remove.
Use sudo pico /etc/paths inside the terminal window and change the entries to the one you want to remove, then open a new terminal session.
when you login, or start a bash shell, environment variables are loaded/configured according to .bashrc, or .bash_profile. Whatever export you are doing, it's valid only for current session. so export PATH=/Applications/SenchaSDKTools-2.0.0-beta3:$PATH this command is getting executed each time you are opening a shell, you can override it, but again that's for the current session only. edit the .bashrc file to suite your need. If it's saying permission denied, perhaps the file is write-protected, a link to some other file (many organisations keep a master .bashrc file and gives each user a link of it to their home dir, you can copy the file instead of link and the start adding content to it)
Close the terminal(End the current session). Open it again.
If the manual export $PATH method does not seem to be working after you close the terminal and open again, definitely check the shell configuration files.
I found a small script that kept adding some more path in front of the $PATH everytime it was open.
For zsh you can check the ~/.zshrc file.

when i type commands in the terminal i get an error - "command not found"

gal-harths-iMac:~ galharth$ ruby -v
-bash: ruby: command not found
gal-harths-iMac:~ galharth$ open -e .bash_profile
-bash: open: command not found
what shoud i do?
my .bash_profile and .profile and .bashrc are empty, i need to write something in them?..
I suspect that you have something overriding your default path (like .bash_profile or .bashrc) open is a valid command on os x, for me man open returns
NAME
open -- open files and directories
SYNOPSIS
open [-e] [-t] [-f] [-W] [-R] [-n] [-g] [-h] [-b bundle_identifier]
[-a application] file ... [--args arg1 ...]
DESCRIPTION
The open command opens a file (or a directory or URL), just as if you had
double-clicked the file's icon. If no application name is specified, the
default application as determined via LaunchServices is used to open the
specified files.....
Likewise it is possible ruby is installed but not on the path. My best guess would be to delete or rename your .bashrc and .bash_profile files and log off as that user and log back in, to reset your bash session.
To test if it is a user level issue, create a new account under system preferences -> accounts and then log in as that user, open a terminal and type ruby -v or man open, etc to see if you can do it on a default user account. If that works, it is most certainly some bash settings you have customized in your 'gal-harth' account.
The first step to figuring out what's gone wrong is to see what your current PATH is.
echo $PATH
If that returns a blank line, something has gone horribly wrong. You can fix it temporarily by running:
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
And that should get you ruby, as well as open, and man, and a bunch of other commands.
The thing is, the PATH says “Look in these directories for binary files” and not “Here is an explicit list of binary files I want to use.”
Ruby is not installed. You need to install it from their website here.
Similarly, "open" is not any bash command I've ever heard of.
Upon further reflection, are you trying to install rvm?
If you have already installed Ruby, is its location already set in your PATH variable? If not, you can add it to your .bash_profile like this:
echo 'export PATH=/wherever/ruby/is/located:$PATH' >> ~/.bash_profile
Something is screwing up your PATH -- you shouldn't need to have a .profile (or any of its variants) to have the default PATH set properly. Generally, when the PATH gets screwed up, it's because it's being set wrong in one of the various profile files. When you say .bash_profile and .profile and .bashrc are empty, do you mean they exist but don't have anything in them, or they don't exist at all? Also, do you have a .bash_login or .bashrc file?
I'd take a closer look around your home directory. Use /bin/ls -ld ~/.* to list all of the invisible files in your home directory, and look for anything with "sh", "profile", or "rc" in the name. Also, run /usr/bin/grep PATH ~/.* to see if any of the invisible files mention PATH -- if any do, they're likely suspects.
just type bash_filename or ./_filename

Resources