NewServerLife
Rackmount servers
NVMe servers
AMD Based
Tower servers
Blade servers
Have any questions?
Get in touch.
Live Chat

Working basics with the bash command shell in Linux

26 September 2023

One of the most important components in Linux distributions is the Bash command shell. It performs functions of reading and running commands, allows you to work with files as well as execute scripts. For the full functioning of operating systems of the Linux family, using Bash also plays an important role.

This review contains important information that will be useful for anyone just getting started with Linux.

What is Bash? Bash meaning.

Bash (Bourne again shell) – an improved version of the Bourne-shell software shell. It is a command processor that runs interactively in a text window. Bash is used for:

  • accepting user commands,
  • sending them to the operating system for the next processing.

What is Bash? Bash meaning

Bash is also a scripting programming language (it allows the creation of scripts to automate various operations). Using Bash in some cases allows you to avoid installing specialized software, since Bash is a convenient and multifunctional tool for performing a wide range of tasks.

History of Bash creation

In 1978, British scientist Stephen Bourne created the Bourne-shell (previous version of Bash). It became one of the first shells for Unix operating systems.

In 1987, programmer Brian Fox decided to increase the number of functions performed and improve Bourne-shell as a whole. A beta version of Bash was created in 1989. Brian Fox continued to maintain and improve his development until 1993.

Brian Fox is the creator of the Bash routine

Brian Fox is the creator of the Bash routine.

The main features, commands and rules for writing them from the original sh shell were transferred to Bash. Other features were taken from Korn Shell and C Shell. It should also be noted that Bash almost 100 percent met the POSIX standards.

A special terminal (including gnome-terminal, lxterm, eterm, xterm) provides interaction between the shell and the operating system. The Bash shell is pre-installed on most Unix/Linux distributions.

Syntax

Bash writing rules are an extended Bourne-shell syntax. The Bash Reference Manual offers everything you need to know about the basics of interacting with the shell (including specification of individual commands).

Example script

Let's consider an example of a script that displays the inscription “Hello world”:

#!/usr/bin/env bash
echo 'Hello World!'

This script consists of two lines:

  • First line tells the operating system about the necessity to run the file using the Bash shell.
  • Second line specifies an action to be performed by the script. This action should print the appropriate message in the terminal window.

Example bash script

Difference between Bash and Bourne-shell

Almost all important Bourne-shell scripts can be executed by Bash on Linux without any modifications. only scripts that require Bourne-shell embedded commands are exceptions.

Bash syntax uses techniques from the Korn Shell and C Shell:

  • Variables $PPID and $RANDOM;
  • Command line editing;
  • Rules for replacing commands $(…);
  • Output of command history;
  • Creating directory stacks.

The Bash console can also be used as an interactive interpreter to autocomplete names of files, commands, variables and programs by pressing the Tab (↹) key.

Applying Bash. What is Bash for?

Working basics with the bash command shell in Linux

Examples of using Bash:

  • Clear the terminal screen.
  • Output the specified number of lines from the log.
  • Find and create a selection of keywords, saving them in a new file.
  • Recursively replace the owners of the specified files and folders.
  • Create an archive of a directory with files and send it via a specific network protocol to another computer on the same network.
  • Find duplicate files on the disk, display a list of them, and delete them if needed.
  • Configure the system for creating backup copies of database files using dumping.
  • Send a request for the configuration of other computers on the network.
  • Suspend running tasks and restart previously suspended ones.

Important advantages

Despite the fact that many different variations of Bourne-Shell have been developed today, the Bash command interpreter still has a number of advantages over them:

  • Supports working with arrays in Linux.
  • Supports the <<< “here strings’’ syntax.
  • Supports coprocesses with <> redirection.
  • Works with .{png,jpg} extensions.
  • Provides an opportunity to work with [[ structures (in sh only [ is available with restrictions).
  • The variables $RANDOM, $SECONDS, $PIPESTATUS[@] and $FUNCNAME are extensions in Bash.
  • Many extensions available using C standards (including an ability to assign increment +=, three-argument loops for((i=0;i<=3;i++)) etc.).
  • A large set of extensions for non-standard configurations is available (+ changing the register).
  • Redirection aliases available, like Csh, like &| for 2>&1 | and &> for >...2>&1.
  • Significantly increased arithmetic capabilities.
  • Interactive features are available in large numbers.

Principle of working with Bash

Using the example of connecting to a web server (where the site files are located) with an installed Linux distribution via SSH from scratch, let's consider how to use Bash.

Working basics with the bash command shell in Linux

We are considering a server with Ubuntu (the principle is the same for other distributions):

  1. The Linux Terminal program automatically launches Bash (after entering login and password).
  2. The invitation is displayed basically as standard and looks like this:

    <username>@<computer name>:<current directory><sign>.

    Working basics with the bash command shell in Linux

    In the example:

    • the username is blurred;
    • vPro – computer name;
    • The grapheme tilde ~ in Linux means the user's home folder in short form (/home/user);
    • $ – indicates that the user does not have administrative rights (hash sign # is displayed if the user is running as an administrator).
  3. After sending the invitation, the terminal will automatically put a space and will wait for commands to be entered. In the image below the “Enter” was pressed. The next line contains the command cd to move to the existing directory /opt. The last line shows the result of the output – the working folder has become /opt and this is displayed in the invitation.

    Working basics with the bash command shell in Linux

  4. Using the Linux command line, it can be possible to run any application installed on the system. Directories with a list of executable programs are usually located in the /bin, /usr/bin folders. The interpreter stores the checked directories in the $PATH variable. their list can be viewed by using the following command:

    echo $PATH

  5. You can also use the ls command and add one of the directories found in $PATH to have an opportunity to see a list of available programs.

    Working basics with the bash command shell in Linux

  6. If it is a console application, Bash will run it in the terminal. An example of launching the Nano editor is considered below.

    Working basics with the bash command shell in Linux

  7. Bash also has an ability to run apps in the background. To do this, you should add an ampersand & at the end after entering the program name.

    Working basics with the bash command shell in Linux

    The line [2] 23258 is the process number and PID. Nano is in the background. You can return to it using the command jobs or fg.

    Working basics with the bash command shell in Linux

    Considering that a wide range of commands can work in the background, you can check the number of the required one using the bg command.

    Working basics with the bash command shell in Linux

Conclusion

The interpreter has many more useful embedded commands. Using these commands, you will be able to perform all the necessary workflows with the web server. For working with arrays and lines of text data in the console environment of Unix operating systems, you can use some of these commands.


Specialists of our company are ready to help you purchase the server and select the necessary server configuration for any required task.


Hot price
DELL PowerEdge R630 10SFF
DELL PowerEdge R630 10SFF
from $398 $0
Configure
Hot price
DELL PowerEdge R630 24x1.8"SFF
DELL PowerEdge R630 24x1.8"SFF
from $588 $0
Configure
Hot price
Dell PowerEdge R630 10SFF (4x NVMe U.2)
Dell PowerEdge R630 10SFF (4x NVMe U.2)
from $569 $0
Configure
Hot price
DELL PowerEdge R630 8SFF
DELL PowerEdge R630 8SFF
from $399 $0
Configure
1/4
Hot price
Dell PowerEdge R640 8SFF
Dell PowerEdge R640 8SFF
from $615 $0
Configure
Hot price
Dell PowerEdge R640 10SFF
Dell PowerEdge R640 10SFF
from $696 $0
Configure
Hot price
Dell PowerEdge R640 10SFF + 2SFF
Dell PowerEdge R640 10SFF + 2SFF
from $645 $0
Configure
Hot price
Dell PowerEdge R640 10SFF (8x NVMe)
Dell PowerEdge R640 10SFF (8x NVMe)
from $765 $0
Configure
Hot price
Dell PowerEdge R640 4LFF
Dell PowerEdge R640 4LFF
from $715 $0
Configure
Hot price
Dell PowerEdge R640 10SFF (10x NVMe)
Dell PowerEdge R640 10SFF (10x NVMe)
from $956 $0
Configure
Hot price
Dell PowerEdge R640 10SFF (4x NVMe)
Dell PowerEdge R640 10SFF (4x NVMe)
from $746 $0
Configure
1/7
Hot price
Dell PowerEdge R730 8SFF
Dell PowerEdge R730 8SFF
from $368 $0
Configure
Hot price
Dell PowerEdge R730 16SFF
Dell PowerEdge R730 16SFF
from $388 $0
Configure
Hot price
Dell PowerEdge R730 8LFF
Dell PowerEdge R730 8LFF
from $478 $0
Configure
1/3
Hot price
Dell PowerEdge R730xd 12LFF + 4LFF + 2SFF
Dell PowerEdge R730xd 12LFF + 4LFF + 2SFF
from $528 $0
Configure
Hot price
Dell PowerEdge R730xd 26SFF (4x NVMe U.2)
Dell PowerEdge R730xd 26SFF (4x NVMe U.2)
from $558 $0
Configure
Hot price
Dell PowerEdge R730xd 26SFF
Dell PowerEdge R730xd 26SFF
from $428 $0
Configure
Hot price
Dell PowerEdge R730xd 24SFF (4x NVMe U.2)
Dell PowerEdge R730xd 24SFF (4x NVMe U.2)
from $508 $0
Configure
Hot price
Dell PowerEdge R730xd 12LFF + 2SFF
Dell PowerEdge R730xd 12LFF + 2SFF
from $488 $0
Configure
Hot price
Dell PowerEdge R730xd 12LFF
Dell PowerEdge R730xd 12LFF
from $448 $0
Configure
Hot price
Dell PowerEdge R730xd 24SFF
Dell PowerEdge R730xd 24SFF
from $398 $0
Configure
1/7
Hot price
Dell PowerEdge R740 8LFF
Dell PowerEdge R740 8LFF
from $1,100 $0
Configure
Hot price
Dell PowerEdge R740 16SFF
Dell PowerEdge R740 16SFF
from $859 $0
Configure
Hot price
Dell PowerEdge R740 8SFF
Dell PowerEdge R740 8SFF
from $809 $0
Configure
1/3
Hot price
Dell PowerEdge R740xd2 24LFF + 2LFF
Dell PowerEdge R740xd2 24LFF + 2LFF
from $2,450 $0
Configure
Hot price
Dell PowerEdge R740xd 24SFF (12 NVMe)
Dell PowerEdge R740xd 24SFF (12 NVMe)
from $1,309 $0
Configure
Hot price
Dell PowerEdge R740xd 24SFF (24 NVMe)
Dell PowerEdge R740xd 24SFF (24 NVMe)
from $1,509 $0
Configure
Hot price
Dell PowerEdge R740xd 24SFF
Dell PowerEdge R740xd 24SFF
from $1,000 $0
Configure
Hot price
Dell PowerEdge R740xd 12LFF
Dell PowerEdge R740xd 12LFF
from $1,109 $0
Configure
Hot price
Dell PowerEdge R740xd 12LFF + 4LFF + 2LFF
Dell PowerEdge R740xd 12LFF + 4LFF + 2LFF
from $1,289 $0
Configure
Hot price
Dell PowerEdge R740xd 12LFF + 4SFF
Dell PowerEdge R740xd 12LFF + 4SFF
from $1,130 $0
Configure
Hot price
Dell PowerEdge R740xd 24SFF (8 NVMe)
Dell PowerEdge R740xd 24SFF (8 NVMe)
from $1,259 $0
Configure
Hot price
Dell PowerEdge R740xd 24SFF (4 NVMe)
Dell PowerEdge R740xd 24SFF (4 NVMe)
from $1,109 $0
Configure
1/9
Hot price
HPE ProLiant DL360 Gen10 8SFF
HPE ProLiant DL360 Gen10 8SFF
from $820 $0
Configure
Hot price
HPE ProLiant DL360 Gen10 8SFF + 2NVMe
HPE ProLiant DL360 Gen10 8SFF + 2NVMe
from $1,270 $0
Configure
Hot price
HPE ProLiant DL360 Gen10 4LFF
HPE ProLiant DL360 Gen10 4LFF
from $845 $0
Configure
Hot price
HPE ProLiant DL360 Gen10 10NVMe Premium
HPE ProLiant DL360 Gen10 10NVMe Premium
from $2,490 $0
Configure
1/4
Hot price
HPE ProLiant DL360 Gen9 8SFF
HPE ProLiant DL360 Gen9 8SFF
from $353 $0
Configure
Hot price
HPE ProLiant DL360 Gen9 10SFF
HPE ProLiant DL360 Gen9 10SFF
from $448 $0
Configure
Hot price
HPE ProLiant DL360 Gen9 4LFF
HPE ProLiant DL360 Gen9 4LFF
from $363 $0
Configure
1/3
Hot price
HPE ProLiant DL380 Gen10 16SFF
HPE ProLiant DL380 Gen10 16SFF
from $955 $0
Configure
Hot price
HPE ProLiant DL380 Gen10 24SFF
HPE ProLiant DL380 Gen10 24SFF
from $1,015 $0
Configure
Hot price
HPE ProLiant DL380 Gen10 16SFF (8x NVMe)
HPE ProLiant DL380 Gen10 16SFF (8x NVMe)
from $1,165 $0
Configure
Hot price
HPE ProLiant DL380 Gen10 24SFF (8x NVMe)
HPE ProLiant DL380 Gen10 24SFF (8x NVMe)
from $1,365 $0
Configure
Hot price
HPE ProLiant DL380 Gen10 16SFF + 2NVMe
HPE ProLiant DL380 Gen10 16SFF + 2NVMe
from $1,085 $0
Configure
Hot price
HPE ProLiant DL380 Gen10 12LFF
HPE ProLiant DL380 Gen10 12LFF
from $1,040 $0
Configure
Hot price
HPE ProLiant DL380 Gen10 8LFF
HPE ProLiant DL380 Gen10 8LFF
from $975 $0
Configure
Hot price
HPE ProLiant DL380 Gen10 8SFF
HPE ProLiant DL380 Gen10 8SFF
from $785 $0
Configure
1/8
Hot price
HPE ProLiant DL380 Gen9 24SFF
HPE ProLiant DL380 Gen9 24SFF
from $468 $0
Configure
Hot price
HPE ProLiant DL380 Gen9 12LFF
HPE ProLiant DL380 Gen9 12LFF
from $483 $0
Configure
Hot price
HPE ProLiant DL380 Gen9 8SFF + 2SFF
HPE ProLiant DL380 Gen9 8SFF + 2SFF
from $448 $0
Configure
Hot price
HPE ProLiant DL380 Gen9 12LFF + 3LFF
HPE ProLiant DL380 Gen9 12LFF + 3LFF
from $518 $0
Configure
Hot price
HPE ProLiant DL380 Gen9 8SFF
HPE ProLiant DL380 Gen9 8SFF
from $363 $0
Configure
Hot price
HPE ProLiant DL380 Gen9 12LFF + 2SFF
HPE ProLiant DL380 Gen9 12LFF + 2SFF
from $478 $0
Configure
Hot price
HPE ProLiant DL380 Gen9 16SFF
HPE ProLiant DL380 Gen9 16SFF
from $458 $0
Configure
1/7