-
Locate the path to the interpreter for the language you are writing in with the
whichcommand.which node which python which bash which ruby -
Add that path as an interpreter directive (using
#!) on the first line of your script. For example ifwhich nodereturned/usr/local/bin/node, the first line of your script should be:#! /usr/local/bin/node -
Write your script to do what you want.
-
Give your script execute permissions for your user with
chmod +x <path_to_your_script>. For example if your script is calledmyScript.jsand is located in your current directory:chmod u+x myScript.js -
Move your script to one of the directories in the path. You can discover which directories are in your path by typing
echo $PATHinto the command line, which will print a colon seperated list of each of the directories in your path. A common directory in the path for scripts you've written is/usr/local/bin/. You will probably need to usesudoto be able to move your file into that directory. If the script you've written has a file extension in its name, and/or some case, like camel case you'd rather modify, be sure to remove the extension and change the name of the script as you wish. Continuing with the example script calledmyScript.js:sudo mv myScript.js /usr/local/bin/my_script -
Use your script you're done. Tab completion will now work when you want to run your script, and
which my_scriptwill disclose its location. If you need to make edits just open the file in its new location and go to town.
-
-
Save roppa/b392b81c3d927f7ada4f to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment