Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Having a bit of trouble finding the answer to my question, perhaps because I may be asking the wrong question.

I understand bash scripts. I write them all the time to do little helpful things repeatedly.

However I would like to know the difference between a shell script, and a program that runs in a shell. For example, what is pine? What language is it written in? It runs in a shell, but as far as I know it's not a shell script, it's a self-contained program that you can navigate around in, and when you exit, you return to the shell exactly where you were when you launched it.

If I wanted to write a program that functions similar to pine, in that it runs in the shell as a program with various functionality, where would I begin? Where can I find some examples of programs written in this way?

share|improve this question
add comment

1 Answer

up vote 9 down vote accepted

I think you're confusing a shell (a command line interpreter) with a terminal emulator.

A shell, when run interactively and pine require a terminal or terminal emulator to interact with the user. pine has nothing to do with the shell though.

A terminal in the older days was a device with a monitor and keyboard connected to a computer over a serial line to interact with the computer (which itself had no monitor or keyboard). The interface is simple and text based.

The serial line on the computer is a character device file (something like /dev/ttyS0 on Linux for instance). Applications that interact with the terminal write data to that device for display on the terminal.

For instance, in the simplest case, pine writing ASCII a to /dev/ttyS0 would cause the sequence of bits corresponding to that a character to be sent over the serial line, and the terminal displays a a on the screen at the current cursor position.

And when the user presses a on the keyboard, in the simplest case, the terminal sends that same sequence of bits on the other wire that goes to the computer and the system puts the a character on a buffer, and when pine does a read() on /dev/ttyS0, it returns that a character.

Terminals have evolved from a things like tele-typewriters (no screen, the a was printed on paper) to ones with CRT monitors, then some with more an more capabilities like cursor positioning, region clearing/scrolling, colour support all of which pine uses, or even graphical capabilities. X later provided with a much more advanced way to interact with a computer this time over a network instead of serial line and windowing capabilities and this time using a much more complex protocol than just a sequence of characters to be sent and a few escape sequences.

Still, decades of applications had been written for the terminal. There are a lot of things that can be done with the terminal that can't be done with X. Because the data is just two streams of characters going in both directions, it's easy for instance to export a terminal session over the network (think telnet, ssh), and an application like cat can be used to write to a terminal to display the content of a file for the user to view on his screen and can be used the exact same way, unmodified for that same content to be stored in a file or sent over the network to some server... (all is needed is redirect where that output goes). The same kind of thing can't be done with X applications that generally have one usage and can't cooperate with each other easily.

For those reasons and more, terminals have always been in use even long after X was wild-spread.

Only, now, instead of having real terminals, we have terminal emulators like xterm, gnome-terminal, eterm... Those emulate a terminal but are just themselves X applications (that run on the computer and are displayed on a X server, on the same computer or another).

By default, when you start such a terminal emulator application, a shell is started in them, which is why there's sometimes confusion between the two. You don't have to run a shell in a terminal emulator, pine doesn't have to be started by a shell, but it does require a terminal. It is a semi-graphic terminal application. It interacts with a terminal device, and at the other end of that device, it expects a terminal or terminal emulator with a minimal set of capabilities like cursor positioning, standout character highlighting...

share|improve this answer
    
These would make nice complements to What is the exact difference between a 'terminal', a 'shell', a 'tty' and a 'console'? (which I've been meaning to improve for ages). –  Gilles Sep 29 '13 at 23:52
    
Great information in general. I eventually found exactly what I was looking for: ncurses. –  CptSupermrkt Oct 6 '13 at 19:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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