What is the correct Zsh shebang?

This is probably a very silly question, but what is the correct shebang for macOS shell scripts?

  • #!/bin/zsh
  • or #!/usr/bin/zsh
  • or #!/usr/bin/env zsh?

This is the best one because others can run the file if their zsh is in a different location than yours.

6 Likes

I have two zsh installations on my Mac:

âžś where zsh
/opt/homebrew/bin/zsh
/bin/zsh

The first is manually installed by me using Homebrew; the second is the one included in macOS.

1 Like

Damm, I always leave off that final “?”!

:slight_smile:

3 Likes

Many thanks, cornchip!

And is usr/ required? That is, is it correct to say that it must be exaclty #!/usr/bin/env zsh and not #!/bin/env zsh?

It should be /usr/bin/env. You can type /usr/bin/env into terminal to see all the paths it’ll be searching.

1 Like

I’m intrigued to know what makes /usr/bin/env universal, but not /usr/bin/zsh?

In my Unix experience, every time you switch to a different flavour, stuff has a habit of being somewhere else. Is /usr/bin/env at least a POSIX standard?

As far as I can see from searching, it isn’t a POSIX standard. It’s just a de facto standard. Meaning it could break on a really old system, which probably isn’t likely nowadays.

3 Likes

This is the only correct Shebang. :joy::joy:

1 Like