Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • nitpick: sh -c /path/to/program will not run program as a shell script if it's missing the executable bits, sh /path/to/program will. sh -c /path/to/program will just open a shell and run /path/to/program as a command in that shell, which will fail if it's not executable. Commented Apr 9, 2018 at 18:49
  • Well, if we are nitpicking, we are both wrong. sh -c /path/to/program reads commands from /path/to/program as input to the shell. It does not require that the file have execute permission but it should be a shell script Commented Apr 11, 2018 at 7:24
  • Hmmm, sh /path/to/program does that. Just tried that myself: echo echo hello world >abc.sh, then sh ./abc.sh prints hello world, while sh -c ./abc.sh says sh: ./abc.sh: Permission denied (which is the same as if you'd run ./abc.sh in the current shell directly.) Did I miss something? (Or maybe I didn't express myself well in the previous comment...) Commented Apr 11, 2018 at 23:20
  • My fault. sh -c _something_ is the same as just typing _something_ at the command prompt, except for the spawning of the inferior shell. So you are correct that it will fail if missing the execute bit (as a file). On the other hand, you can provide a series of shell commands like sh -c "echo hello world" and it will work just fine. So it doesn't require that what you type have the execute bit (or even be a file), only that the shell interpreter can do something with it. Commented Apr 11, 2018 at 23:49
  • I believe the OP was referring to some compiled or system executable, so execute permission was assumed. Commented Apr 11, 2018 at 23:52