-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
  • 3
    Welcome to Software Engineering Stack Exchange :) Do you mean shell? Commented May 30, 2020 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 Commented May 30, 2020 at 11:31
  • I think the question-tags could be more specific. Commented Jun 1, 2020 at 9:31

2 Answers 2

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.

6
  • 1
    Welcome to Software Engineering Stack Exchange :) How does your answer address the question OP has posted? Commented May 30, 2020 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. Commented May 30, 2020 at 12:39
  • low level of a shell look like -> look a source code of sh -> more low level ? -> look the kernel. Commented May 30, 2020 at 12:46
  • or low level of terminal/console -> look at st source code. Commented May 30, 2020 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. Commented May 30, 2020 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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.