Mac terminal keeps giving message - macos

Whenever I open my terminal on my mac I get this message, -bash: /usr/local/bin: is a directory
How do I remove this? As I find it annoying and unneeded.

There is probably a line trying to execute /usr/local/bin (which is a directory and not a executable) in either your ~/.bash_profile or your ~/.bashrc
If you want to view the contents of these files (as you asked above) you can type in your terminal after you open it:
cat ~/.bash_profile
and
cat ~/.bashrc
You can try to verify what lines mention /usr/local/bin by typing these commands:
cat ~/.bash_profile | grep "/usr/local/bin"
and
cat ~/.bashrc | grep "/usr/local/bin"

Related

zsh is not Recognizing an Environmental Variable - No such File or Directory - Unix - MacOs

Expected behavior
List the documents in a directory using an environmental variable.
Steps to Reproduce
INPUT
$ export ICLOUD_D="~/Library/Mobile\ Documents/com~apple~CloudDocs/"
$ source ~/.zshrc
$ echo $ICLOUD_D
$ ls $ICLOUD_D
OUTPUT
$ ~/Library/Mobile\ Documents/com~apple~CloudDocs/
$ ls: ~/Library/Mobile\ Documents/com~apple~CloudDocs/: No such file or directory
Current behavior
Shell gives me a: No such file or directory error.
Steps Performed Thus Far to Fix
If I were to simply cut and paste the file path with the command ls then I'm able to list the files as expected.
I've also tried to put quotes around the environmental variable as well.
$ ls "$ICLOUD_D"
System information
- OS: MacOS v 10.15
- Shell: zsh
Do not put quotes around the environmental variable
INPUT
$ export ICLOUD_D=~/Library/Mobile\ Documents/com~apple~CloudDocs/
$ source ~/.zshrc
$ echo $ICLOUD_D
$ ls $ICLOUD_D
OUTPUT
$ ~/Library/Mobile\ Documents/com~apple~CloudDocs/
$ afile
$ bfile
$ ...

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

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

How do I make a command in cygwin to run Sublime Text?

I'm trying to mimic the subl command in iterm for mac computers in cygwin.
Basically, I want to be able to open a current folder from cygwin by typing subl .
I haven't found any good instructions. I know where my .bashrc file is located. I just dont know what to do to create the command subl and make it so that the path following subl opens with Sublime.
Can anyone help?
You'd want to make an alias and source it from bashrc.
Example
Create a file ~/.bash_aliases with:
alias subl='/cygdrive/c/sublime.exe' #make sure this command is correct for you
Now in ~/.bashrc do:
source ~/.bash_aliases
Log out and log back in, and subl . should work
Assuming you want correct behaviour when doing subl ~, a simple alias or adding Sublime Text to your PATH will not work.
You can use the following bash function instead (put it in your .bashrc):
function subl {
cygpath --windows $# | sed 's/\\/\\\\/g' | tr '\n' '\0' | xargs -0 -n1 /cygdrive/c/Program\ Files/Sublime\ Text\ 3/subl.exe
}
Note that when passing paths to xargs you need to 1) escape the backslashes, 2) use the NUL character as argument delimiter for it to work with paths with spaces.
Edit: Use subl.exe rather than sublime_text3.exe so that it would detach itself from the terminal.
To open files and use Git tools (commit, rebase, tag, ... messages):
#!/bin/bash
# To create in [.babun/]cygwin/usr/local/bin/subl with chmod +x
ARGS=""
while test $# -gt 0
do
ARGS="$ARGS ${1#/cygdrive/[a-zA-Z]}"; # Remove /cygdrive and disk letter from the path
shift
done
/cygdrive/c/Program\ Files/Sublime\ Text\ 3/subl.exe $ARGS
https://gist.github.com/cmalard/16c58869319c9a88473ec08cc7989c6b
You can also simply add Sublime to your PATH variable. For cygwin, you can:
Go to your home directory and verify .bash_profile exists with ls -a
Open .bash_profile with something like vim .bash_profile
add the line export PATH=$PATH:"/cygdrive/c/Program Files/Sublime Text 3" (or whatever top level installation folder Sublime is in)
Reopen your terminal and use subl to verify it works

Git for Windows doesn't execute my .bashrc file

I've just installed Git for Windows 2.5.0 on Windows 7, and it appears that my .bashrc file is not being executed when I run Git Bash.
I created the file like so:
Administrator#HintTech-Dev MINGW64 /
$ pwd
/
Administrator#HintTech-Dev MINGW64 /
$ cd ~
Administrator#HintTech-Dev MINGW64 ~
$ pwd
/c/Users/Administrator
Administrator#HintTech-Dev MINGW64 ~
$ touch .bashrc
Administrator#HintTech-Dev MINGW64 ~
$ vi .bashrc
[... I insert the line "ZZZTESTVAR=234" (without the quotes) into the file in vim ...]
Administrator#HintTech-Dev MINGW64 ~
$ exit
Yet, when I next run Git Bash:
Administrator#HintTech-Dev MINGW64 /
$ set | grep ZZZ
Administrator#HintTech-Dev MINGW64 /
$ cat ~/.bashrc
ZZZTESTVAR=234
Administrator#HintTech-Dev MINGW64 /
$ ZZZTESTVAR=234
Administrator#HintTech-Dev MINGW64 /
$ set | grep ZZZ
ZZZTESTVAR=234
Administrator#HintTech-Dev MINGW64 /
$
Why isn't my .bashrc being run? It seems to be in the right place and have the right permissions.
OK, I found out the problem. Quite simply, the bash terminal used by the latest Git for Windows 2.5.0 (mintty) doesn't bother to read .bashrc - it reads .bash_profile. So you can set up your environment in .bash_profile and/or put this code at the start to read .bashrc:
if [ -f ~/.bashrc ]
then
. ~/.bashrc
fi
Same thing happened to me when I upgraded to Git Bash 2.5.0 in Windows 10. I renamed my '.bashrc' -> '.bash_profile' and relaunched Git Bash. Everything's working as usual again.
mv ~/.bashrc ~/.bash_profile
It appears the latest version of git for Windows (2.8.3.windows.1) uses a 'profile' file now instead of the .bash_profile. I assume this is so it isn't hidden and a valid file name. Didn't seem to cause any issues before, but maybe it was confusing to people.
A bit late on this answer perhaps, but you could call bash with the -rcfile argument followed by the location of your .bashrc file.
bash -rcfile C:\Users\name\.bashrc
I've added this to the end of my PowerShell profile (.ps1 file) so that Powershell automatically opens in bash and configured to my preferences.

terminal cant do ls or cd

Can anybody explain what is wrong with my terminal:
$ echo $PATH
=/usr/local/bin
$ ls
-bash: ls: command not found
$ cd
-bash: find: command not found
Why won't these commands work? Help? Anyone?
I'm guessing your .bash_profile or .bashrc has a line that looks like
export PATH=/usr/local/bin
This is overwriting all the existing stuff that needs to be in your $PATH. You need to change this line to look like
export PATH=/usr/local/bin:$PATH
"ls" lives in "/bin" and "find" lives in "/usr/bin". You need to add these to your $PATH in your bash_profile or .bashrc.

Resources