Uninstalled Anaconda still shows up in PATH (Mac OS X) - bash

I have installed Anaconda a few months ago but then uninstalled it and removed all anaconda files by using
rm -rf ~/anaconda
but when I run
echo $PATH
it still outputs a path that point to an Anaconda folder but when I search for it, it doesn't even exist, why is that happening?

What makes you think that non-existent directory are automatically
removed from $PATH? They are not. As an example I can make a new dir
and go there:
$ mkdir /tmp/new-path-dir && cd /tmp/new-path-dir
Add it to the $PATH:
$ PATH=/tmp/new-path-dir:$PATH
$ echo $PATH
/tmp/new-path-dir:<REST_OF_PATH>
Make a new olleh.so (hello spelled backwards) executable inside
it:
$ echo 'echo hi' > olleh.so && chmod +x olleh.so
Then go back to ~:
$ cd ~
And start a olleh.so:
$ olleh.so
hi
Now I can safely remove /tmp/new-path-dir:
$ rm -r /tmp/new-path-dir/
And it still will be shown in my $PATH:
$ echo $PATH
/tmp/new-path-dir:<REST_OF_PATH>
But I won't be able to run olleh.so any more:
$ olleh.so
bash: /tmp/new-path-dir/olleh.so: No such file or directory
And as paths to executables are cached by bash I can get rid of
olleh.so permanently like this:
$ hash -r
$ olleh.so
bash: olleh.so: command not found

Related

bash scripting - what does "ls .." (ls with double dot) do?

My homework asked me to find what ls .. does.
I tried to search the internet but I couldn't find any answer to the question.
Does someone know what this command does?
.. is an entry in the current directory that refers to the parent of the current directory. It's not a special convention used just by ls. For example:
$ cd /usr/bin
$ pwd
/usr/bin
$ cd ..
$ pwd
/usr
$ [ -d .. ] && echo "It's a directory"
It's a directory
$ stat ..
<output specific to your installed version of stat>

Can't remove an item in $PATH (Xamarin Workbooks)

The following directory no longer exists on my MacBook Pro after I uninstalled Visual Studio Community Edition for Mac. I can copy and paste it from the $PATH though here:
/Applications/Xamarin Workbooks.app/Contents/SharedSupport/path-bin
It's still in the $PATH but I can't tell where it is being set
~ $ grep -n SharedSupport ${HOME}/.bash_profile
~ $ grep -n SharedSupport ${HOME}/.bashrc
~ $ grep -n SharedSupport ${HOME}/.profile
~ $ grep -n SharedSupport ${HOME}/.zshrc
~ $ grep -n SharedSupport ${HOME}/.zprofile
~ $ grep -n SharedSupport ${HOME}/.zlogin
Any ideas how to remove it from the $PATH? I uninstalled it so naturally the terminal can't find the folder. Now I can't find where it's being exported to PATH so I can remove it.
Just figured it out! Turns out it stores its paths in a file in /etc/paths.d called Xamarian, like Jonathan Leffler commented. So in order to delete it, we'll need to:
Open a terminal, this can be iTerm, Terminal, etc.
CD Into the Directory
cd /etc/paths.d
Remove the file called xamarian with rm,
rm -rf xamarian
That's it!
In my case, there is a file called workbooks in /etc/paths.d.
Open the file by vim and edit it

Unexpected behavior from shell script's ln -sfn -v

I have the following:
if [ $kernel == 'Darwin' ]; then
$HOME="/Users/$user"
elif [ $kernel == 'Linux' ]; then
$HOME="/home/$user"
fi
# Let the script know what the dotfiles dir is
dotfiles_dir="$HOME/dotfiles"
# Making symlinks to shell files, add yours as you need
echo 'Making symlinks to shell files'
ln -sfn -v $dotfiles_dir/shells/zsh $HOME/.zsh
ln -sfn -v $dotfiles_dir/shells/zsh/zshrc $HOME/.zshrc
ln -sfn -v $dotfiles_dir/shells/bash $HOME/.bash
ln -sfn -v $dotfiles_dir/shells/bash/bash_profile $HOME/.bash_profile
ln -sfn -v $dotfiles_dir/shells/bash/bashrc $HOME/.bashrc
ln -sfn -v $dotfiles_dir/shells/profile $HOME/.profile
echo "Done at [$time]...\n"
However, this strangely outputs:
[Other output here...]
Making symlinks shell files
/Users/eduan/.zsh -> /Users/eduan/dotfiles/shells/zsh
/Users/eduan/.zshrc -> /Users/eduan/dotfiles/shells/zsh/zshrc
/Users/eduan/.bash -> /Users/eduan/dotfiles/shells/bash
./bashrc -> /Users/eduan/dotfiles/shells/bash/bashrc
/Users/eduan/.profile -> /Users/eduan/dotfiles/shells/profile
Done at [08:15]...
[Other output here...]
Can anybody tell me why I get this unexpected output? The rest of my symlinks are generated correctly, however the Bash symlinks are messed up for some reason.
BTW, this is in a big script that generates symlinks. This is only part of it, and I put the relevant parts, so that you don't get confused. :)
EDIT:
Here's the link to the latest version of the script: https://github.com/Greduan/dotfiles/blob/master/scripts/make_symlinks.sh
The darwin version of the symlink commands is missing the destination for bashrc, so going to the current directory.
I'm not sure why there are two versions of that bit of the script?
Also you only create the backup directory if it already exists, which can't be right?
This line is wrong, isn't it. Missing destination directory.
ln -sfn -v $dotfiles_dir/shells/bash/bashrc

How can I return to the previous working directory quickly in Bash?

When I change into a directory with the cd command, I lose the previous working directory, unless I remember it in my memory. Is there some handy method to go back quickly?
Demo:
$ cd ~/some_path
$ cd /another_path
$ command_to_go_back_to_some_path
You can go back to the last dir with cd -
You can also do this
$ pushd ~/some_path
$ pushd /another_path
$ popd
$ popd
As mentioned you can use cd -. The shell internally does a cd $OLDPWD.
For usage in a script, you could use the OLDPWD shell variable: it contains the previous working directory.
$ pwd
/home/username
$ cd /usr/bin
$ pwd
/usr/bin
$ cd "$OLDPWD"
$ pwd
/home/username
I prefer this over cd - in scripts because I don't have to suppress any output.
If you want to use it in a script and suppress the output, do this:
cd - > /dev/null

Space in directory name creating problem

I am trying to build some code and the location where the compiler is present has a space in it 'blahblah/Source Code/blahblah' .I am not sure how to add this to the environment variable.I use bash and tried to use the normal
export PATH="$PATH:/blahblah/Source Code/blahblah"
but it doesnt seem to work(I also tried using \before spaces).Throws me errors like No such file or directory.Am I missing out on something?
I just did a little experimentation on my own:
$ mkdir 'Source Code'
$ cd Source\ Code/
$ vim testme.pl
$ chmod 755 testme.pl
$ cat testme.pl
#! /usr/bin/perl
print "I worked\n";
$ ./testme.pl
I worked
$ cd ..
$ export PATH="$PATH:/home/bchittenden/Source Code"
$ testme.pl
I worked
This indicates that the problem is not the whitespace in $PATH... bash seems to handle that correctly... you'll have to give us more information.

Resources