macOS – Terminal Can’t Execute Files in Current Working Directory

bashcatalinacommand linemacosterminal

I stated having this behaviour recently when I tried executing my sh script via sh my_script.sh.

It was a simple script with some pyinstaller command.
Now, the issue that I'm having is that my terminal is not able to access/read file in present directory.

If I give ls, I can see the file in the directory, but when I try to run that file, my terminal just shows
zsh: command not found: hulusubs_dl_osx

Binary file that I'm trying to run is hulusubs_dl_osx.

xonshiz@MacBook-Pro Downloads % ls
Bills           
Notes
Some Important Things
hulusubs_dl_osx
xonshiz@MacBook-Pro Downloads % hulusubs_dl_osx
zsh: command not found: hulusubs_dl_osx
xonshiz@MacBook-Pro Downloads % 

As you can see that the file hulusubs_dl_osx shows up, but when I try to access it, I get command not found error.

But, if I were to provide full path to that file, then terminal is able to run that file

xonshiz@MacBook-Pro Downloads % ls                                       
Bills           
Notes
Some Important Things
hulusubs_dl_osx
xonshiz@MacBook-Pro Downloads % hulusubs_dl_osx                          
zsh: command not found: hulusubs_dl_osx
xonshiz@MacBook-Pro Downloads % /Users/xonshiz/Downloads/hulusubs_dl_osx --version
2021.01.08.3
xonshiz@MacBook-Pro Downloads % 

I can access my other installations like Python, brew etc., just fine. But, I can't access any file. It's not just the case with this hulusubs_dl file, but with any given file. I was able to run the file directly few days ago.

Does anyone have any clue what might be happening? What I might've changed that caused this?

P.S: I'm on Catalina

Best Answer

If no path is given (either an absolute or a relative one) the shell searches through the directories listed in $PATH to find commands to execute. If the current directory isn't included there, you need to use a relative path like

./hulusubs_dl_osx

In theory you could solve this by adding . to PATH but this is considered bad practice due to the potential security risk (imagine somebody putting a fake ls command in one of your directories).