-5

Good day everyone.

I am planning to build a terminal, which will support common commands like ls, cd, cat, etc. But I am confused on how I should structure my codebase so that if in future, I decide to support more advanced commands, it shouldn't have to be a total re-write. I checked out the official linux source code, but found it kind of cryptic and confusing.

In simple words, how should a low-level design of a terminal look like?

  • 3
    Welcome to Software Engineering Stack Exchange :) Do you mean shell? – Nimesh Neema May 30 at 11:31
  • Sharing your research helps everyone. Tell us what you've tried and why it didn't meet your needs. This demonstrates that you've taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer. Also see How to Ask – gnat May 30 at 11:31
  • I think the question-tags could be more specific. – knb Jun 1 at 9:31
1

You can be looking for a shell like: bash, sh, korn, zsh, fish.

Roughly speaking,they are languages for interact with the kernel. And those have the ability to support ls, cd... (I don't have a clue, witch one of those should be better to look into the source code)

Or you can be looking to make a terminal/console software which it has no relation with supporting commands such like ls, cd... (you have a terminal/console in windows as well), and if you want to make one of those at low level I'd recomend to take a look to, the "simple terminal" of suckless.

| improve this answer | |
  • 1
    Welcome to Software Engineering Stack Exchange :) How does your answer address the question OP has posted? – Nimesh Neema May 30 at 12:36
  • @NimeshNeema By indicating that there's a difference between terminal and shell, and that OP should look at bash instead of the Linux kernel. – amon May 30 at 12:39
  • low level of a shell look like -> look a source code of sh -> more low level ? -> look the kernel. – Bepitic May 30 at 12:46
  • or low level of terminal/console -> look at st source code. – Bepitic May 30 at 12:48
  • 2
    Actually, with the exception of cd, all of those are simply programs like any other program. cd needs to be a shell builtin because, at least in POSIX, a program cannot manipulate its parent process's environment, but all the other ones don't need to be shell builtins and typically aren't. – Jörg W Mittag May 30 at 13:27
2

A bit of clarification: A terminal or console is the window where you type the commands, but the shell is the program which interprets and executes the commands. So your question is about implementing a shell.

Some commands may be built-in in the shell language, but typically they are just external programs. So if you type "foo", the shell looks in the path for a "foo" program and executes it. This is extremely flexible because you don't have to touch the shell code at all to add a new command, you just place an independent program somewhere on the path.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.