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)