Search code examples
shellcommandshzsh

How to make zsh run executable script file with zsh by default?


After I switched from bash to zsh, one thing is bothering me while running executable scripts.

When I used bash, if I run some script like:

./test.sh

bash will run this script with bash

But if I do the same thing in zsh, it will run that with sh. Is it possible to change this default behavior of zsh?

Maybe using #! is a solution but I'm trying to find another method fixing that by just setting once.


Solution

  • This answer is provided by @Gairfowl: POSIX is ambiguous about what should happen. There does not appear to be a way to change the default behavior in any shell, and adding hashbangs is probably the only consistent method to get the behavior you want.