/
En-Scripts

There are two ways to execute a shell script (.sh files) from a terminal:

Shell Interpreter

The first way is to directly give it to a shell interpreter like so:

$ sh hello-world.sh

That should work for most scripts, but if using sh gives you issues, try bash instead.

Direct Execution

This method involves running it like any other executable:

$ ./hello-world.sh

If it doesn't work and you get ./hello-world.sh: cannot execute - Permission denied, then you need to mark it as executable. To mark it, do this:

$ chmod +x hello-world.sh

chmod adds the flag executable (+x) for hello-world.sh. Now, you can run it like any other executable-- give ./hello-world.sh another shot. It should work this time.

Page last modified on March 09, 2018, at 03:12 AM
Powered by PmWiki + ☭ + ♥