Score:1

Difference between executing .sh/.bash program with sh/bash and executing it directly

cn flag

If we have a program start.sh, we can execute it with the sh start.sh. But we could execute it giving permission with chmod and run ./start.sh in the command line. What is the difference between those two ways of executing a bash/sh script.

Score:1
iq flag

They both execute shell script but there is some little difference:

sh will use will use the sh interpreter even if a differenter interpreter was indicated in the begining of the file like #!/bin/bash this can be useful if you want your script to be executed using always the same interpreter

for ./start.sh the shell will try to execute as an executable file so the script need a shebang like #!/bin/bash so ./start.sh is more flexible since you can use the interpreter you want

terdon avatar
cn flag
You don't _need_ a shebang actually. `./start.sh` will still work even without one. I was just testing and I can't quite figure out if it runs using whatever the default `$SHELL` is or not. When I was running a bash shell, it ran with `bash` but from a `zsh` and `dash` shell, it ran with `/bin/sh`. In any case, the main point is that even without a shebang, an executable file containing shell commands can be run with `./script.sh`.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.