38
loading...
This website collects cookies to deliver better user experience
~./bashrc
After writing a .js
file or other kinds of files, you could run it with node
or other runtime tools.
In the ~./bashrc
, we could make use of alias
to help us run those files in a much easier way
For example to execute node abcd.js
, we could make it with as simple as only one word abcd
Here is how we could do it
alias abcd="node /var/local/abcd.js"
The down side of writing alias
in ~./bashrc
is that the script can only be used by the users whose ~./bashrc
has those script.
If there are multiple accounts in the server, you could not make sure that everyone could use that shortcut
/usr/local/bin
An executable is a file which is set to be executed
In that file, you specify how the script is run
Using the above abcd
as an example, what you need is the following
cd /usr/local/bin
touch abcd
chmod a+x ./abcd # enable execution for all groups
# edit the executable
vim abcd
# ------- vim abcd -------
#!bin/bash
node "/var/local/abcd.js"
# ------- vim abcd -------
By doing so, every user could use the abcd
command
If the abcd.js
accepts 3 arguments, which you include something like let [ var1, var2, var 3] = process.argv.slice(2)
in your .js
file to get the arguments , you could further do this
# ------- vim abcd -------
#!bin/bash
node "/var/local/abcd.js" $1 $2 $3
# ------- vim abcd -------
abcd
in your system. Input your newly created command into your console and see if it could run as expected. If I did anything wrong, please let me know as well. That's all for today. I hope you enjoy reading.