Why isn't symlink in application being found in $PATH in OSX? - macos

I've always been a little wobbly on OSX environment variables, but I figured that, so long as /usr/local/bin was in my $PATH, that everything residing in that folder would be usable as a command in the shell.
This doesn't appear to be happening. $ echo $PATH gives me:
/Users/[username]/.nvm/versions/node/v0.12.7/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
My /usr/local/bin folder contains a symlink to an application; let's call it some-application. But typing some-application in the shell yields the classic bash error:
-bash: some-application: command not found

It was a simple mistake on my part. I had created the symlink using a bad link location:
$ ln -s /some/non-existent/location/some-application /usr/local/bin/some-application
There was no error on creating this 'link'. The symlink name was the one used in the bash error, masking the fact that it couldn't find the original location, not the link.
For me, I would have either expected an error to be thrown on creation of the link, or at least for bash to detail which path couldn't be resolved. Something like this:
-bash: /some/non-existent/location/some-application: No such file or directory
Oh well. Case closed.
P.S
Any light being shed on why it behaves this way might be helpful to myself and others.

Related

Why do self made symlinks/aliases in /usr/local/bin not work as expected with 'which' command?

I've been creating bash scripts recently, and would like to store them in my /usr/local/bin directory. When I ls this directory, I see many, what I believe to be, symlink paths. Example:
brew -> /usr/local/HomeBrew/bin/brew
I've been able to successfully create symlinks to my own scripts and stored them in my /usr/local/bin with the ln command:
ln -s /User/me/Projects/bash/my_script /usr/local/bin/my_script
and everything runs as expected.
The problem I'm encountering, is when I to try run which my_script it's not returning a nice stdout result, like it is with the other scripts. For example running which brew returns: /usr/local/bin/brew in a nice stdout format to use with other commands.
Running which my_script, will successfully detect my script but, returns
my_script: aliased to ~/Projects/bash/my_script
This makes combining with other commands more difficult.
Can anyone explain what the difference is, and how I could possibly fix this?
You must have defined an alias named my_script, which is shadowing your symbolic link. You can do a
type -a my_script
to find all definitions. To bypass the alias, invoke it using
command my_script
Aside from this: Are you sure that you really want a link from /usr/local/bin into something which is below your /User/me? This does not look sane to me. Wouldn't it be better to simply put /User/me/Projects/bash into your PATH?

Windows PATH seems broken in Git Bash

I installed MySQL and wanted to see if it worked well, testing it on Git Bash (the course told me to do so). The code I had to write was the following one: export PATH=/c/Program Files/MySQL/MySQL Server 8.0/bin/:$PATH.
The main issue is that every time I open again Git Bash there are several lines saying not a valid identifier. I can't provide an image as I'm new, but one of the examples might be:
bash: export: `Corporation/NVIDIA': not a valid identifier
Although I deleted Git Bash and reinstalled again, the problem persists. Does anyone know how to fix that on Windows?
Thanks in advance!
Because the path contains spaces, it needs to be quoted:
export PATH="/c/Program Files/MySQL/MySQL Server 8.0/bin/:$PATH"
You need to change this in whatever file you originally wrote this line in; it's probably named .bashrc or .bash_profile and can be found in your home directory (typically c:\Users\YourUsername).

source /.bash_profile command not working

I am trying to refresh my aliases on my Mac (OS Catalina 10.15.6) after defining new aliases in my .bash_profile file with the command:
source ~/.bash_profile
But terminal keeps giving this error message:-bash: s: command not found
This is confusing because for the longest time this command worked. I even had it included in my .bash_profile file as an alias, where it worked fine.
I'm aware the problem could have to do it with an error in my PATH but I've never made any edits to my PATH so have no idea what the issue could be?
Thanks in advance.
My first instinct would be to check both ~/.bashrc, and /etc/bashrc if it exists. That is where I customarily define aliases, and it looks to me as though a bad alias may be your problem.
I'm not saying it was the one you made, although it might be. Just go through your rc and profile files and look for any aliases which might in any way clash with source.
I suspect the source command is working just fine and the problem is a bad line in the ~/.bash_profile itself that looks like it's trying to run a command named s. I would look in there for the problem.
It might help to run it with xtrace on via bash -x ~/.bash_profile – running it in a separate process like that won't have any of the presumably-desired side effects of sourceing it in your current shell, but you can see what it's trying to do so that you can fix it.
(You can also just set -x before the source and get both xtrace and running in the current shell; just be sure to set +x afterwards or your shell session will be full of debug output.)

Terminal commands can not be found OSX

A majority of terminal commands don't work, for example .
ls
sudo
vi
with the error -bash: ls: command not found my path is echo $PATH
“/Users/username/usr/local/bin I get the feeling that “ should not be there but not sure how edit it.
What should the path be and how do I get the path to stay the same?
You need to add more paths to your $PATH variable. Try running whereis ls and check where is the binary of the command.
You can add more paths like this: export PATH=$PATH:NEW_PATH
I had a similar experience recently where a lot of my terminal commands were not being found despite being clearly saved in my bash_profile. After lengthy process of elimination I realised that the issue was caused when I tried to export a new path. The error that I had made was putting a space in the command. So I had to change
export SOMETHING = /path/to/something.apk to
export SOMETHING=/path/to/something.apk
So I would recommend you check all your path declarations to ensure you don't have any white spaces. Also don't forget to source your bash_profile or what ever type of command line shell you use.

Ubuntu Shellscript Path Variable

I have the following Shellscript that I call from my crontab, which works fine until it calls php code that involves shell commands like wget or find.
#!/bin/sh
PATH=/opt/server/php/bin:/usr/bin/wget:/bin/egrep:/usr/bin/find
cd /opt/server/apache2/htdocs/webapp/
php oil refine job:handler
For each Command I did a which command to look up the path, then I added it to the Path Variable. Nevertheless it does not find the commands and I get messages like these:
sh: wget: not found
sh: find: not found
How would I fix this? I know that this is a common problem, but I didn't find a good explanation for this here on stackoverflow. Also: I know that calling the script from bash versus crontab might result in different enviroment settings, but eitherway I get these Errors.
Good sir, the PATH is a string that describes the directories that contain executables, not the executables themselves.
Perhaps use something like this
PATH=/opt/server/php/bin:/usr/bin:/bin

Resources