3

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>?

1
  • 4
    Note that zsh does not run the script unless you explicitly tell it to with zsh ./run. If you just do ./run, the shell mentioned in the shebang (here, #!/bin.bash) is the shell that will run the script.
    – terdon
    Commented Jun 15, 2021 at 16:11

1 Answer 1

18

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.

2
  • So, bash ./run ./filename.sh ?
    – MaxRocket
    Commented Aug 26 at 14:13
  • 1
    @MaxRocket run is the name of the file to execute mentioned in the question. It doesn’t seem to need an additional argument.
    – nohillside
    Commented Aug 26 at 14:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .