Running shell or Bash scripts with zsh on macOS v11 (Big Sur)

Every time I need to run a shell script, I need to enter

chmod +x <filename>

For example, if I want to run this sample script named "run",

#!/bin/bash

javac --version

I have to go into my terminal

chmod +x run
./run

Is there a way to allow Z shell (zsh) always to run these scripts without having to enter chmod +x <filename>?


Solution 1:

You only need to run chmod once for a script, not each time you run it. If you don‘t want to do this, you can also use bash ./run to execute it.

You can also create a text file with the executable bit set once, and then use it as a template in your editor of choice to create new scripts based on it.