mirror of
https://github.com/ellysh/bash-programming-from-scratch.git
synced 2026-01-12 08:21:52 +00:00
Review the "Development Tools" section
This commit is contained in:
@ -1,93 +1,89 @@
|
||||
## Development tools
|
||||
## Development Tools
|
||||
|
||||
You need a Bash interpreter and a terminal emulator to run the examples of this chapter. They can be installed on all modern operating systems. Let's take a look at how to do this.
|
||||
You need a Bash interpreter and a terminal emulator to run the examples of this chapter. You can install them on all modern operating systems. Let's take a look at how to do this.
|
||||
|
||||
### Bash Interpreter
|
||||
|
||||
Bash is a [**script programming language**](https://en.wikipedia.org/wiki/Scripting_language). Such languages have the following features:
|
||||
Bash is a [**script programming language**](https://en.wikipedia.org/wiki/Scripting_language). It has the following features:
|
||||
|
||||
1. They are interpreted but not compiled.
|
||||
1. It is interpreted language.
|
||||
|
||||
2. They operate existing programs or high-level commands.
|
||||
2. It operates existing programs or high-level commands.
|
||||
|
||||
3. They are integrated into a shell or OS.
|
||||
3. You can use it as a shell to access the OS functions.
|
||||
|
||||
The Bash language is integrated into Linux and macOS. If you use Windows, you should install a minimal Unix environment. Bash needs it for working correctly. Let's look at two ways to set up an environment.
|
||||
If you use Linux or macOS, you have the preinstalled Bash interpreter. If your OS is Windows, you need both Bash interpreter and POSIX-compatible environment. Bash needs this environment to work correctly. There are two ways to install it.
|
||||
|
||||
The terms "Unix-environment" and "Linux-environment" mean a software environment compatible with POSIX standards.
|
||||
I> You can meet the "Unix environment" and "Linux environment" terms. They both mean a software environment that is compatible with POSIX standards.
|
||||
|
||||
The first option is to install the [**MinGW**](https://en.wikipedia.org/wiki/MinGW) toolkit. In addition to the Bash interpreter, it provides the [free GCC compiler](https://en.wikipedia.org/wiki/GNU_Compiler_Collection). The MinGW component called MSYS (Minimal SYStem) is sufficient for the examples of this book. This component includes a Bash interpreter, a terminal emulator, and [GNU utilities](https://en.wikipedia.org/wiki/GNU_Core_Utilities). Together they make up a minimal Unix environment.
|
||||
The first option is to install the [**MinGW**](https://en.wikipedia.org/wiki/MinGW) toolkit. It contains the [GNU compiler collection](https://en.wikipedia.org/wiki/GNU_Compiler_Collection) in addition to Bash. If you do not need all MinGW features, you can install Minimal SYStem (MSYS) instead. MSYS is the MinGW component that includes Bash, a terminal emulator and [GNU utilities](https://en.wikipedia.org/wiki/GNU_Core_Utilities). These three things make up a minimal Unix environment.
|
||||
|
||||
Let's install a version of the Unix environment called [MSYS2](https://www.msys2.org). Before installing it, check the bitness of your Windows operating system. These are steps to take it:
|
||||
It is always good to clarify the bitness of your Windows before installing any software. Here are steps to read it:
|
||||
|
||||
1. If you have a "Computer" icon on your desktop, right-click on it and select "Properties".
|
||||
1. If you have a "Computer" icon on your desktop, right-click on it and select the "Properties" item.
|
||||
|
||||
2. If there is no "Computer" icon on your desktop, click the "Start" button. Find the "Computer" item in the menu. Do right-click on it and select "Properties".
|
||||
2. If there is no "Computer" icon on your desktop, click the "Start" button. Find the "Computer" item in the menu. Right-click on it and select "Properties".
|
||||
|
||||
3. In the "System" window that opens, locate the "System Type" item as Figure 2-1 shows. It shows the bitness of your Windows.
|
||||
3. You have opened the "System" window. Locate the "System Type" item there as Figure 2-1 demonstrates. This item shows you the bitness of Windows.
|
||||
|
||||
{caption: "Figure 2-1. System Type"}
|
||||

|
||||
|
||||
Download the MSYS2 installer from the [official website](https://www.msys2.org). The installer file depends on the bitness of your system:
|
||||
We are going to install the modern MSYS version called MSYS2. Download its installer from the [official website](https://www.msys2.org). You should choose the installer version that fits the bitness of your Windows.
|
||||
|
||||
The number `20190524` in the filename means the version of MSYS2. Select the latest available version.
|
||||
|
||||
Now let's install MSYS2. These are the steps to take it:
|
||||
Now we have everything to install MSYS2. Follow these steps for doing it:
|
||||
|
||||
1. Run the installer file. You will see the window as Figure 2-2 shows.
|
||||
|
||||
{caption: "Figure 2-2. MSYS2 installation dialog", height: "30%"}
|
||||

|
||||
|
||||
2. Click the "Next" button (next). In the new window (see Figure 2-3), select the installation [**path**](https://en.wikipedia.org/wiki/Path_(computing)) and press the "Next" button.
|
||||
2. Click the "Next" button.
|
||||
|
||||
3. You see the new window as Figure 2-3 shows. Specify the installation [**path**](https://en.wikipedia.org/wiki/Path_(computing)) there and press the "Next" button.
|
||||
|
||||
{caption: "Figure 2-3. Selecting the installation path", height: "30%"}
|
||||

|
||||
|
||||
3. In the next window, you can select the application name for the "Start" menu. Leave it unchanged and click "Next". Then the installation process starts.
|
||||
4. The next window suggests you to choose the application name for the Windows "Start" menu. Leave it unchanged and click the "Next" button. Then the installation process starts.
|
||||
|
||||
4. When the installation is complete, click the "Finish" button. The window will close.
|
||||
4. When the installation finishes, click the "Finish" button. It closes the installer window.
|
||||
|
||||
Now the MSYS2 Unix environment is on your hard drive. Its files are located in the `C:\msys64` directory if you keep the default installation path. Go to this directory and run the application `msys2.exe`. The Bash shell window opens as Figure 2-4 shows.
|
||||
You have installed the MSYS2 Unix environment on your hard drive. You can find its files in the `C:\msys64` directory if you did not change the default installation path. Go to this directory and run the `msys2.exe` file. It opens the window where you can work with the Bash shell. Figure 2-4 shows this window.
|
||||
|
||||
{caption: "Figure 2-4. The Bash shell window", height: "20%"}
|
||||

|
||||
{caption: "Figure 2-4. The Bash shell", height: "20%"}
|
||||

|
||||
|
||||
The second option is to install a Unix environment from Microsoft. It is called [Windows subsystem for Linux](https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux) (WSL). This environment is available for Windows 10 only. It does not work on Windows 8 and 7. You can find the manual to install WSL on the [Microsoft website](https://docs.microsoft.com/ru-ru/windows/wsl/install-win10).
|
||||
The second option is to install a Unix environment from Microsoft. It is called [Windows subsystem for Linux](https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux) (WSL). This environment is available for Windows 10 only. It does not work on Windows 8 and 7. You can find the manual to install WSL on the [Microsoft website](https://docs.microsoft.com/en-us/windows/wsl/install-win10).
|
||||
|
||||
Linux and macOS users do not need to install Bash. It is available on these systems by default.
|
||||
If you use Linux, you do not need to install Bash. You already have it. Just press the shortcut key Ctrl+Alt+T to open a window with the Bash shell.
|
||||
|
||||
Press the shortcut key Ctrl+Alt+T to open the Bash window in Linux.
|
||||
If you use macOS, you have everything to launch Bash too. Here are the steps for doing that:
|
||||
|
||||
These are the steps to launch Bash on macOS:
|
||||
|
||||
1. Launch the Spotlight search program. To do this, click the magnifying glass icon in the upper right corner of the screen.
|
||||
1. Click the magnifying glass icon in the upper right corner of the screen. It opens the Spotlight search program.
|
||||
|
||||
2. The dialog box appears. Enter the text "Terminal" there.
|
||||
|
||||
3. The list of applications opens. Click on the first line with the name "Terminal" there.
|
||||
3. Spotlight shows you a list of applications. Click on the first line in the list with the "Terminal" text.
|
||||
|
||||
### Terminal emulator
|
||||
|
||||
When you launch the application `msys2.exe`, the terminal emulator window opens. An [**emulator**](https://en.wikipedia.org/wiki/Emulator) is a program that simulates the behavior of another program, OS or device. Emulators are used for compatibility. For example, you want to run a Windows program on Linux. To do this, install an emulator of the Windows environment on Linux. It is called [Wine](https://en.wikipedia.org/wiki/Wine_(software)). Wine provides its own version of the Windows system libraries. Thanks to the emulator, you can run the Windows program on Linux.
|
||||
Bash shell is not a regular GUI application. It even does not have its own window. When you run the `msys2.exe` file, it opens a window of the terminal emulator program.
|
||||
|
||||
The terminal emulator solves the compatibility problem. Command-line programs are designed to work through a terminal device. Today, nobody uses terminals. Personal computers and laptops have replaced them. To run a program that works only with the terminal, you need a terminal emulator. It sends the program's commands to the shell and displays the results on the screen.
|
||||
An [**emulator**](https://en.wikipedia.org/wiki/Emulator) is a program that simulates the behavior of another program, OS or device. The emulator solves the compatibility task. For example, you want to run a Windows program on Linux. There are several ways to do that. One option is using the emulator of the Windows environment for Linux. It is called [Wine](https://en.wikipedia.org/wiki/Wine_(software)). Wine provides its own version of the Windows system libraries. When you run your program, it uses these libraries and supposes that it works on Windows.
|
||||
|
||||
Figure 2-5 shows the interaction between input/output devices, the terminal emulator, the shell and the command-line program.
|
||||
The terminal emulator solves the compatibility task too. Command-line programs are designed to work through a terminal device. Nobody uses such devices today. Cheap personal computers and laptops have replaced them. However, there are still many programs that require a terminal for working. You can run them using the terminal emulator. It uses the shell to pass data to the program. When the program returns some result, the shell receives them and passes to the terminal emulator. Then the emulator displays the results on the screen.
|
||||
|
||||
Figure 2-5 explains the interaction between input/output devices, the terminal emulator, the shell and the command-line program.
|
||||
|
||||
{caption: "Figure 2-5. The workflow of the terminal emulator", height: "25%"}
|
||||

|
||||
|
||||
There are two lines in the terminal window after startup (see Figure 2-4):
|
||||
The terminal emulator window in Figure 2-4 shows the following two lines:
|
||||
{line-numbers: false}
|
||||
```
|
||||
ilya.shpigor@DESKTOP-1NBVQM4 MSYS ~
|
||||
$
|
||||
```
|
||||
|
||||
The first line starts with the username. In my case, it equals `ilya.shpigor`. Then there is the computer name `DESKTOP-1NBVQM4` after the symbol @. You can change this name via Windows settings. The word `MSYS` comes next. It means the name of the platform where Bash is running. At the end of the line, there is the symbol ~. It is the **absolute path** to the current directory. Let's pay attention to this point.
|
||||
|
||||
There are two types of paths to file system objects: absolute and relative. The address bar of Windows Explorer shows the paths of the first type. An absolute path is a path to the same file system object regardless of the current directory. **Relative path** specifies the path concerning the current directory.
|
||||
|
||||
Relative paths are shorter than absolute paths. That is why they are faster to type and easier to use in shells. There is a simple rule to distinguish the type of paths in the Unix environment. Absolute paths start with a slash /. For example, `/c/Windows/system32`. Relative paths start with a directory name. For example, `Windows/system32`.
|
||||
The first line starts with the username. The username is `ilya.shpigor` in my case. Then there is the @ symbol and the computer name `DESKTOP-1NBVQM4`. You can change the computer name via Windows settings. The word `MSYS` comes next. It means the platform where Bash is running. At the end of the line, there is the symbol ~. It is the path to the current directory.
|
||||
|
||||
@ -396,7 +396,7 @@ The software dependency looks different in Linux. Most of the utilities are free
|
||||
|
||||
The interaction of programs is crucial in Linux. Even monolithic graphical Linux applications usually provide a command-line interface. This way, they fit smoothly into the ecosystem. It leads that you can integrate them with other utilities and applications.
|
||||
|
||||
Suppose that you are solving a complex task in Linux. You should assemble a single computing process from a combination of highly specialized utilities. It means that you make a computation algorithm that can be complex by itself. Linux provides a tool for this specific task. The tool is called [shell](https://en.wikipedia.org/wiki/Unix_shell). Using the shell, you type commands and the system performs them. The first Unix shell appeared in 1979. It was called [Bourne shell](https://en.wikipedia.org/wiki/Bourne_shell). Now it is deprecated. The [Bash](https://en.wikipedia.org/wiki/Bash_(Unix_shell)) shell has replaced it in most Linux distributions. We will consider Bash in this book.
|
||||
Suppose that you are solving a complex task in Linux. You should assemble a single computing process from a combination of highly specialized utilities. It means that you make a computation algorithm that can be complex by itself. Linux provides a tool for this specific task. The tool is called [shell](https://en.wikipedia.org/wiki/Unix_shell). Using the shell, you type commands and the system performs them. The first Unix shell appeared in 1979. It was called [Bourne shell](https://en.wikipedia.org/wiki/Bourne_shell). Now it is deprecated. The [Bash](https://en.wikipedia.org/wiki/Bash_(Unix_shell)) shell has replaced it in most Linux distributions. We will consider Bash in this book.
|
||||
|
||||
We have considered Linux and Windows cultures. You cannot give a preference to one or another. Comparing them causes endless disputes on the Internet. Each culture has its advantages and disadvantages. For example, the Window-style monolithic applications cope well the tasks that require intensive calculations. When you combine specialized Linux utilities for the same task, you get an overhead. The overhead happens because of launching many utilities and transferring data between them. This requires extra time. As a result, you wait longer to complete your task.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user