0

I understand bash as a window where I can type commands to linux. Reading the wikipedia, I've learned that there were various shell applications throughout the history. First, I understood bash as something where you type a command and get a response. Every time you typed something and pressed enter, it would respond with another line of text with the response. But it's more than that. You can actually create 'applications' inside bash. For example, there are the text editors nano and vim. So it looks that you can actually control some graphs inside the window.

Another example is this window that appears in the raspi-config command of the raspberry pi. This appears inside the putty window when I type this command. What is it? How do I make colorful and rectangular things appear inside bash?

I want to understand what's happening: where does bash runs inside linux? how does it communicate with the system? I'm young and therefore I have no insight on the history of terminals on computers, I don't know how all changed when GUIs appeared.

enter image description here

marked as duplicate by jasonwryan, G-Man, Archemar, mikeserv, Raphael Ahrens Nov 30 '15 at 9:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 7
    unix.stackexchange.com/questions/4126/… might be helpful to take a look at. – casey Nov 30 '15 at 3:44
  • That rasp-config command is using a package called whiptail to draw the ASCII art menu with ANSI colors and whiptail is actually a replacement for the dialog command. whiptail uses the newt shared library to do the lower-level drawing of the menus which is a replacement for GNU ncurses (which is an alternative to BSD curses.) – Derek Callaway Feb 28 '18 at 13:59
3

There are a few levels of abstraction involved in presenting what you see in the screenshot you provided. I will attempt to summarize, although this is a rather broad topic.

Terminal Emulator

What you describe:

a window where I can type commands to linux

is not actually bash, at least not by itself. You are looking at a terminal emulator that runs your shell (probably /bin/bash).

The oft-quoted example of a terminal emulator is xterm, which is included in virtually all desktop Unix and Linux systems. However, there are many terminal emulators, some of which have substantially more features than xterm, such as additional mouse controls, tabs (similar to browser tabs), etc.

Linux console (a.k.a. "text mode")

You can also use your Linux machine like a physical terminal, which is what you would see when you boot a Linux/Unix system without a graphical environment (as is the case with many systems configured as servers). Linux still abstracts these somewhat (allowing multiple virtual terminals on one physical computer), but effectively these resemble your monitor being a dedicated "text-only" display.

Shell

The terminal emulator can run any command-line program it likes. By default, it just runs an interactive shell (e.g., bash, sh, csh, ksh, etc.). So, what is a shell?

Quite simply, a shell is a command-line program like any other. If run in interactive mode (i.e., not running a pre-programmed shell script), it presents you with a prompt (usually something like type_outcast:~$), and then takes whatever you type and interprets it according to its own set of rules (language). Every shell is a bit different, but most of the common shells are broadly similar.

What happens when you type a command?

When you type a command (for example, ls -l) and pressing Enter, the shell looks at the string you typed and decides what to do. In this case, it looks for a program called ls in your $PATH variable, and when it finds it, it runs it in a child process (fork() and exec() system calls if you want to know the internals) with the argument you supplied (-l).

The command's output (known as stdout or the "standard output", also stderr or "standard error") are, by default, hooked up to the terminal, so you see the output of your program. Similarly, stdin ("standard input") is hooked up by default as well, so you can type inputs to interactive programs. (Sometimes the program will take more direct control of the terminal, which is an intermediate programming topic.)

Commands' input and output can be redirected, which is another fairly broad topic in itself.

What about all those fancy colors and menus?

Most terminal emulators accept color and various control codes (typically ANSI escape sequences, plus a few more terminal-specific codes). These codes can be used to draw colored interfaces, such as the dialog you see in your screenshot.

In other words, there is no significantly new voodoo here. My system in the early 80s (long before Windows came around) understood ANSI codes and displayed similar dialogs, when my terminal was simply an 80x25 color (EGA) monitor.

So what has changed?

Relatively little has changed since then, except perhaps for the far more widespread prevalence of graphical desktops, which inspired terminal emulator applications, so that people could enjoy larger terminal dimensions as well as have their terminals run alongside their graphical applications, instead of having to dedicate their monitor and keyboard to an 80x25 or 80x43 text-only display.

  • there are very few terminal emulators with substantially more features than xterm - tabs, for example, are fundamentally supported by xterm in that it is embeddable into any other X window. and the Linux console is a terminal emulator. a physical terminal is a piece of hardware. – mikeserv Nov 30 '15 at 4:30
  • @mikeserv I'm a little surprised you find that statement contentious, although obviously it is somewhat open to interpretation. Since it was an aside to give context, and not a critical part of my answer, I'll weaken the quantifier to "some". Does that satisfy your objection? If not, please elaborate, or let me know how I can improve it. – type_outcast Nov 30 '15 at 5:30
  • 1
    it surprised me because xterm is the most feature-full terminal emulator of which i am aware, though, in honesty, most of its features are of the kind that require a little bit of configuring. i mean, how many other terminal emulators come with a tektronix drawing mode? still, the linux console is not a physical terminal. – mikeserv Nov 30 '15 at 5:34
  • @mikeserv Your point about physical terminals is well-taken; that was clumsy wording on my part, which I will correct shortly. Thanks for the catch! As for the rest, though, I don't want to argue with you. – type_outcast Nov 30 '15 at 7:59

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