The Advent of CLI - Day 1

Let’s explains some base vocabulary


The Command-line

Or more exactly the Command Line Interface, the CLI

Usually the end user (you, me, everybody) interact with a personal computer
using programs, and usually programs with a graphic interface: that is
programs with a GUI (Graphical User Interface).

You know those GUI, they have buttons, sounds, colors, icons, graphics, etc.
you manipulate thoses graphics with an input device like a mouse, a touch screen, a gamepad, etc.

CLI programs on the other end do not have such graphics, they deal with text,
usually you use your keyboard to enter text commands and the CLI program output text.

Wikipedia’s Command-line interface definition is right on the point

A command-line interface (CLI) is a means of interacting with a
computer program where the user (or client) issues commands to the program
in the form of successive lines of text (command lines).
The program which handles the interface is called a command-line interpreter
or command-line processor.


To interact with the CLI, you will usually launch a terminal, or a console, or a shell,
and you will be faced with a Command prompt

A command prompt (or just prompt) is a sequence of (one or more) characters
used in a command-line interface to indicate readiness to accept commands.
It literally prompts the user to take action. A prompt usually ends with one of the
characters $, %, #, :, > and often includes other information,
such as the path of the current working directory and the hostname.


Don’t get confused by different terms: terminal, console, shell, etc.
from this article What’s the difference between a console, a terminal, and a shell?
we gonna explain those right now


A Terminal

The word Terminal comes from terminate, indicating that it’s the terminating end or “terminal” end of a communications process. You’ll often hear “dumb terminal” when referring to a text-based environment where the computer you are sitting next to is just taking input and showing text while the real work happens at the other end in a mainframe or large computer.

TTY or “teletypewriter” was the first kind of terminal. Rather than a screen you’d have a literal typewriter in front of you. When you type on it, you’re seeing the text on a piece of paper AND inputing that text into a computer. When that computer replies, you’ll see the typewriter automatically type on the same paper.

image_60e4a888-c894-4b70-98a8-74aa4b8d208c

When we refer to a Terminal in the software sense, we’re referring to a literal software version of a TTY or Terminal. The Windows Terminal is that. It’s really good at displaying textual output. It can take input and pass it on. But the Terminal isn’t smart. It doesn’t actually process your input, it doesn’t look at your files or think.

That’s about it, the terminal or TTY (TeleTYpe) is a computer program that is really good at displaying text and accepting text input, it does not interpret it though, eg. it is not a command-line interpreter or command-line processor.


A Console

Folks in the mid 20th century would have a piece of furniture in their living room called a console or console cabinet. A Console in the context of computers is a console or cabinet with a screen and keyboard combined inside it. But, it’s effectively a Terminal. Technically the Console is the device and the Terminal is now the software program inside the Console.

image_13b2c80d-a2d6-4429-8ca6-f053340897cc

In the software world a Terminal and a Console are, for all intents, synonymous

Yep, terminal or console, that is about the same thing, it is where we input and display the text.


A Shell

A shell is the program that the terminal sends user input to.
The shell generates output and passes it back to the terminal for display.
Here’s some examples of Shells:

  • bash, fish, zsh, ksh, sh, tsch
  • PowerShell, pwsh
  • cygwin
  • cmd, yori, 4dos, command.com

Here’s an important point that should make more sense now that you have these terminals - Your choice of shell doesn’t and shouldn’t dictate your choice of terminal application.

So, just a slight correction (that you can ignore for now if you want), Cygwin “as is” is not a shell but a Linux emulation layer, it provides POSIX API and translate them to Windows API.

And to continue with Cygwin, when you install it, by default it provides MinTTY as a console/terminal application and Bash as a shell.

And to get into even more details (that you can still ignore)

Aside: WSL and WSL2 (the Windows Subsystem for Linux) are a complete local Linux (or many Linuxes) that run on Windows 10. They are full and real. WSL2 ships a real Linux kernel and runs in on Windows. Cygwin is NOT a Linux. Cygwin is a large collection of GNU and Open Source tools which provide functionality similar to Linux on Windows - but it is not Linux. It’s a simulacrum. It’s GNU utils compiled against Win32. It’s great, but it’s important for you to know what the difference is. Cygwin may let you run your shell scripts but it will NOT run Apache, Docker, or other real ELF-binaries and Linux apps.


Pseudo Something

Anything you can call a Pseudo Console, Pseudo Terminal, PTY, Pseudo TTY (CONPTY)

Pseudo Terminals are terminal emulators or software interfaces that emulate terminals.
They pretend to be terminals like the ones above.
*Nix systems have long had a pseudo-terminal (PTY) infrastructure
and now Windows as a pseudoconsole (ConPTY) as well.

image_e3c2af63-3682-44c6-89b3-4c7d09f0fcf4

So if you have time and want to go deep into the subject, read this blog post
The TTY demystified

if you don’t have time, just keep this in mind

In present time, we find ourselves in a world where physical teletypes and video terminals are practically extinct. Unless you visit a museum or a hardware enthusiast, all the TTYs you’re likely to see will be emulated video terminals — software simulations of the real thing.

Yes, that’s right, you do not have access to real terminales and consoles, every single ones are emulators.


The Default You Usually Get

Under a Linux Ubuntu Desktop

the default terminal is gnome-terminal, you also have xterm
and the default shell is bash

more in details

  • usually you get bash v4 or later
    which has more features than the default bash v3.2 found on macOS
  • when you boot a Linux system the terminal is the Linux console

    The Linux console (and Linux virtual consoles) are implemented by the VT subsystem of the Linux kernel, and do not rely on any user space software. This is in contrast to a terminal emulator, which is a user space process that emulates a terminal, and is typically used in a graphical display environment.

Under macOS Desktop

the default terminal is Terminal.app
and the default shell is bash

more in details

  • from Mac OS X 10.0 to Mac OS X 10.2
    the default shell was tcsh
  • from Mac OS X 10.3, OS X 10.8 to macOS 10.14
    the default shell was bash 3.2
  • since macOS 10.15
    the default shell is zsh

Read Moving to zsh

The bash binary bundled with macOS has been stuck on version 3.2 for a long time now. bash v4 was released in 2009 and bash v5 in January 2019. The reason Apple has not switched to these newer versions is that they are licensed with GPL v3. bash v3 is still GPL v2.

Under Windows Desktop

the default terminal is the Windows Console
and the default shell is CMD, or cmd, or cmd.exe, also known as “Command Prompt”

more in details

  • from Windows XP to Windows 8.1
    the Windows Console terminal emulation did not receive a lot of TLC
    see The Evolution of the Windows Command-Line
  • since Windows 10
    Microsoft improved a lot the terminal emulation providing support for
    • UTF-8 and UTF-16 (including CJK ideograms and emojis)
    • 24-bit color
    • ANSI/VT sequences
    • etc.

Read


At this point, people usually ask

  • what console should I use?
  • what shell should I use?

it is bit like “what programming language should I pick first to learn programming?”

it depends, there are various answers, nothing is really wrong

but here for the sake of the exercice, I will make the choice for you and explain why


for Windows 10

I will not cover Windows 10 S, Windows 8.1, Windows 7 or even older Windows


for macOS

  • use the default Terminal.app

it should work from Mac OS X 10.3 (Panther) to macOS 10.5 (Catalina)

Note:
for macOS 10.5 (Catalina)
you will have to change your default shell to bash instead of zsh


for Linux

  • favour a Debian or Ubuntu, ideally Ubuntu 18.04 LTS
  • use the default gnome-terminal

it should work for older versions as far as Ubuntu 14.04


for anything else

  • install a Virtual Machine, for ex VirtualBox
  • and install an Ubuntu 18.04 LTS (Desktop or Server)

And for each ones of them we will consider Bash (v3.2) as our default shell
to learn command-line stuff from now on.

Why?

For OS like Linux and macOS the default terminals are good enough
and support the default things we want like UTF-8, ANSI, etc.

For OS like Windows, we go with the latest like the Windows Terminal
as it is what is the closest to a proper terminal emulator and it supports
default things like UTF-8, ANSI, etc.

Ubuntu is one of the most installed Linux on the cloud (AWS, GCP, Azure)
and with WSL integrate very well with Windows (we will see that later)

Bash (Bourne Again Shell) is the most cross-platform shell you could use,
in most case it will be there by default, later you will have not too much trouble
picking up another shell if you want to.

So yes all this is extremely biased but believe me those are good defaults to start and learn, later on (or even during) I will try to show big and small differences between different shells etc.

2 Likes

I prefer iTerm2 as a terminal app on my Mac. It’s so much more powerful than the default Terminal.app

yep no prob, there are tons of terminal emulators for macOS/Linux
that keep correct features

I just try to make it beginner friendly and force the choice of the terminal as “default”

later on people can go in many directions for terminal emulators, shells, etc.

1 Like