2

I'm trying to set up a keybinding for an executable which is in my home. For this, I set the command:
sh -c '\"/path/to/the/executable\" --options'
But, it does not work, and, when I'm running it in a terminal, I've got:
not found (or no such file or directory with bash)

As @n. m. could be an AI says in a comment of this question

when you try to run an executable and get a "file not found" error while the file is obviously right here, it's the interpreter missing.

For the executable, the file command gives:
script, Unicode text, UTF-8 text executable

To me, it seems to be a simple script, that sh and bash should be able to execute! What am I missing?

Edit, extra context as requested: this is actually part of the TOR browser, the first line of the script has:

#!/usr/bin/env ./Browser/execdesktop

And the first line of ./Browser/execdesktop has:

#!/usr/bin/env bash
4
  • Maybe you could provide the first, 10-20 lines of code from the file on your question?
    – symcbean
    Commented Jul 9 at 16:04
  • @symcbean, it's the Tor browser. The first line is #!/usr/bin/env ./Browser/execdesktop, and the first list of execdesktop is #!/usr/bin/env bash ^^
    – Phantom
    Commented Jul 9 at 16:31
  • @steeldriver, because I always did, and it used to work. I know that's no a great answer :s
    – Phantom
    Commented Jul 9 at 16:38
  • @steeldriver, When removing it, it works now, thanks!
    – Phantom
    Commented Jul 9 at 16:45

1 Answer 1

10

Your command attempts to run a command called "/path/to/the/executable" - including the double quotes as part of the name:

sh -c '\"/path/to/the/executable\" --options'

This is almost certainly not what you want, and you should either omit the escaped quoted entirely, or remove the backslashes. For example,

date                # Tue,  9 Jul 2024 18:42:00
"date"              # Tue,  9 Jul 2024 18:42:00
\"date\"            # -bash: "date": command not found

sh -c 'date'        # Tue,  9 Jul 2024 18:42:00
sh -c '"date"'      # Tue,  9 Jul 2024 18:42:00
sh -c '\"date\"'    # sh: line 1: "date": command not found

You're probably best setting the binding to this:

/path/to/the/executable --options

Or if executable is already in your $PATH, simply:

executable --options

Now, moving on to the second part of your question. Your "hash bang" line specifies env as the script interpreter, which is a non-intuitive way of telling the system that the next argument can be searched for in the normal way, including being searched down the $PATH

#!/usr/bin/env ./Browser/execdesktop

However, in this situation the command can only be found if the script is executed from a directory that contains Browser/execdesktop. Should you try to execute this script from anywhere else you'll still get an error telling you the command cannot be found.

You would be better either adding the absolute path to execdesktop to your $PATH or specifying an absolute path to the command. For example,

#!/usr/bin/env /home/me/Browser/execdesktop

And at that point you might as well remove the env redirection completely:

#!/home/me/Browser/execdesktop
5
  • 4
    Note that the shebang as per comments has #!/usr/bin/env ./Browser/execdesktop so with the interpreter a relative path, so it will only work if the current working directory is the one that contains the Browser subdirectory. If called from a different directory, you'd probably need /path/to/the/Browser/execdesktop /path/to/the/executable --options Commented Jul 9 at 17:48
  • @StéphaneChazelas if it's not in the question I don't generally consider it Commented Jul 9 at 17:49
  • 1
    It was not the question, but the remark is still relevant :)
    – Phantom
    Commented Jul 9 at 18:08
  • 2
    @Phantom if it's relevant it should be in the question Commented Jul 9 at 20:12
  • 1
    @Phantom answer updated to address the updated question Commented Jul 10 at 8:55

You must log in to answer this question.

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