0

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

2

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).

8
  • Ah, thanks. That worked and thanks for the explanation about the .. However, the weird thing is that I could call any file directly without prepending ./ earlier. I'm just wondering what could've caused this issue. Well, I've accepted your solution, as it works and explanation is there. Thanks again! :)
    – Xonshiz
    Jan 10 at 18:38
  • @Xonshiz Could you run files in the CWD directly, or via another command like sh my_script.sh? (Note: in this case the directories in $PATH are searched for "sh", and then it looks in the CWD for "my_script.sh") Jan 10 at 21:12
  • Yep, I was directly able to call sh my_script.sh and it was working. Like I said, I ran that command and after that this issue started happening. I just checked, I can run this sh command just fine, without prepending ./ to it. But, I can't run any other file/binary without ./.
    – Xonshiz
    Jan 11 at 9:05
  • 1
    @Xonshiz Most probably some of these directories are in your PATH, some are not. ls just lists any directory content, it doesn't care about execution.
    – nohillside
    Jan 11 at 9:28
  • 1
    askubuntu.com/questions/320632/… and unix.stackexchange.com/questions/4430/… have some more details on this
    – nohillside
    Jan 11 at 9:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .