DEV Community

Stephen Charles Weiss
Stephen Charles Weiss

Posted on • Originally published at stephencharlesweiss.com on

Shell Scripts: How To Run Them

I am constantly striving to improve my understanding and comfort interacting with my terminal. I remember how excited I was when I first started to understand how to change my shell from bash to zsh, create persistent aliases, and even begin writing my own functions.

More recently, I’ve been experimenting writing shell scripts when it dawned on me - I didn’t actually know how to run the script. If it were an .html file, I could open it in a web browser. If it were a node application, I could run it from the command line:

$ node my-file.js

But what about a .sh file?

This is one of those questions that once you know how, you forget that you once didn’t. But until you know - it’s not really clear what you’d do.

Imagine you have a directory with a setup script in it:

.
├── node_modules
├── package-lock.json
├── package.json
├── setup.sh
└── src

To execute the setup script, you simply call it:

$ ./setup.sh

In this example, I’m already in the directory where setup lives - but you can imagine if I was up a directory, and it was saved in a directory scripts, I could also call it:

$ ./scripts/setup.sh

You don’t need to preface it with anything (as in the node example) because the shell knows how to execute the shell script!

Top comments (0)