L
L
LINKeR UA2016-05-19 21:54:59
PHP
LINKeR UA, 2016-05-19 21:54:59

How does bash terminal parse a command and what parameters to pass to it?

Hello!
Are there source codes or code examples somewhere on how to create your own command line interface emulator, preferably in PHP? I don't mean a PHP file that passes parameters to the command line. I'm interested in the algorithm itself, how BASH saves aliases, parses parameters, etc. to reproduce something similar in PHP. All that I managed to find was reading the parameters with which the PHP script was launched or how to get the parameters in *.sh. And I would like to see the algorithm of the work of this command itself. Thanks for any link/information!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Belyaev, 2016-05-19
@LINKeRxUA

You won't make a full-fledged bash, don't even try, bash is a full-fledged scripting language, when you reach the level of developing the simplest scripting language, you will no longer have such questions, and the need for this will disappear.
As for parsing the arguments of a separate command, everything is on the conscience of the application that this command launches, bash passes all the arguments simply as a string

A
abcd0x00, 2016-05-20
@abcd0x00

I'm interested in the algorithm itself, how BASH saves aliases, parses parameters, etc. to reproduce something similar in PHP.

Well, this should be done in a loop in which to accept input one line at a time, and when entering a line, parse it into components and save the necessary parts to a hash table (if we are talking about aliases). In bash, aliases also need to be written to a file that is executed each time the interpreter is loaded. That is, there is no secret place there, they are simply loaded into memory and hang there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question