Hi everyone, I am Ekim, a fresh Bootcamp graduate and an IT helper (I don't dare to call myself a programmer yet). Every Friday, I will share some of the work that I've done over the last week in a bid to get feedbacks from you guys and record my journey to become a programmer.
Last week was a hectic journey. I didn't have much time working on blog writing. So this blog wouldn't be as detailed as others I've written. Despite that, I would like to share with you some tips for making your own command on Ubuntu.
- Writing in
After writing a
.jsfile or other kinds of files, you could run it with
nodeor other runtime tools.
~./bashrc, we could make use of
aliasto 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
Here is how we could do it
alias abcd="node /var/local/abcd.js"
The down side of writing
~./bashrcis that the script can only be used by the users whose
~./bashrchas those script.
If there are multiple accounts in the server, you could not make sure that everyone could use that shortcut
- Writing an executable at
An executable is a file which is set to be executed
In that file, you specify how the script is run
Using the above
abcdas 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.jsaccepts 3 arguments, which you include something like
let [ var1, var2, var 3] = process.argv.slice(2)in your
.jsfile to get the arguments , you could further do this
# ------- vim abcd ------- #!bin/bash node "/var/local/abcd.js" $1 $2 $3 # ------- vim abcd -------
Now, you have created a command called
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.