Tuesday, 25 April 2017

How does Linux terminal commands get parse?

In the terminal, or shell, on Linux machines you can type certain commands with options, flags, arguments, etc.

cd /home/user -p

and then when you run the command it get parse and something happen.

I want to make a JavaScript (NodeJS) parser that simply take a string and parse it into tokens so I can use the tokens and execute certain functions how they should execute. Sort of like how Linux shell work.

I was thinking something like this might work.

{
    name: "cd",
    flags: ["p"],
    args: ["/home/user"],
}

I never done any type of parsing. How would I go about creating my goal? Is there any better way to do it or any libraries that does this for you?



via Kurieita

No comments:

Post a Comment