Introduction to basic bash


Foreword
This translated “Slackware Linux Unleashed” (third edition) chapter of the book bash, but made the necessary deletions, the actual situation in some places and made a big change, if necessary, please refer to the original.

Introduction
This will be a more detailed description of Linux, the most commonly used shell, bash. bash (Bourne Again Shell) is the default Linux shell, and is used by most users, in this article you will learn:

What is the shell

The most common shell on Linux

Orders filled (Command-line completion) and wildcard

Command History (Command history) and alias

Redirection and Pipes

Change the prompt

Process Control (Job control)

How to configure your customized bash shell

In addition you will also see some of the most common bash commands and memory usage of variables, finish reading this article you will be faster and more efficient use of bash.

Shells in a Nutshell

What is a shell? In short the word seems to always appear in Linux, but many new users are not aware of its clear meaning. This section will give an exact explanation of why in Linux it seems so important.

What is Shell?

shell is that you (the user) and Linux (or, more accurately, is that you and the Linux kernel) between the interface program. Prompt you for each command by the shell first and then passed to the Linux kernel interpretation.

————————————————– ——————————

Note: If you are familiar with m $-dos, you will recognize this as the DOS is the relationship between the user and COMMAND.COM. CD
A function of the difference is far and command.com shell par.

————————————————– ——————————
shell is a command language interpreter (command-language interpreter). Has its own set of built-in shell commands. In addition, shell can also be other effective system of Linux utilities and applications (utilities and application programs) are called.

Whenever you type a command, which are explained in Linux shell. Some commands, such as printing the current working directory command (pwd), is included in the Linux bash internal (like DOS internal command). Other commands, such as the copy command (cp) and move the command (rm), is present in the file system directory under a separate program. But to the user, you do not know (or may not care) is based on a command shell or within a separate program.

Photo shows how the command shell is explained, shell first checks whether the command is an internal command, not the case then check whether it is an application where the application could be Linux’s own utilities, such as ls and rm, can also be the purchase of commercial programs, such as xv, or public domain software (public domain software), as ghostview. Then shell try the search path to find these applications. Search path is a directory to find a list of executable programs. If you type the command is not an internal command and is not found in the path of this executable file will display an error message. If the command was successfully found, then, shell internal orders or applications will be broken down and passed to the Linux kernel system calls.

Another important feature is the shell itself is an interpreted programming language, shell programming language support in high-level language can see the vast majority of program control structures, such as loops, functions, variables and arrays. shell programming language is very easy How to recover files from formatted disk to learn and once mastered you will become a powerful tool. Any type of command prompt can also be placed in an executable shell program, which means that a shell language can simply repeat a task.

How to start shell
shell you log into the system to successfully start, and always as your means of interaction with the kernel until you exit the system. Each user on your system has a default shell. Each user’s default shell in the passwd file system is specified, the file path is / etc / passwd. passwd file also contains other things: each person’s user ID number, a copy of encrypted password and user login immediately after the procedure (Note: For added security, the system now generally regard the encrypted password in a another file – shadow, while part of the password stored in passwd with a character instead of x) Although not strictly required in this program must be a Linux shell, but most cases are true.

The most common shell
On Linux and UNIX systems can use many different shell can be used. The most commonly used is the Bourne shell (sh), C shell (csh), and the Korn shell (ksh). Three shell have their advantages and disadvantages. Bourne shell was written by Steven Bourne. It is the first use of the UNIX shell on UNIX and in each can be used. Bourne shell, shell programming quite good, but in dealing with user interaction to make was not as good as several other aspects of shell.
C shell written by Bill Joy, it’s considered more user-friendly interface. It supports command-filled as the (command-line completion) and some other Bourne shell does not support the feature. Generally agreed that the C shell programming interface to do as Bourne shell, but the C shell by many C programmers use the C shell syntax, and because the C language is very similar, which is the origin of the name C shell.

Korn shell (ksh) written by the Dave Korn. It combines the C shell and Bourne shell and Bourne shell, and the advantages of fully compatible.

In addition to these outside shell, a shell absorption of many other of these advantages of the original shell process to become the new shell. Common on Linux have tcsh (csh extension), Bourne Again shell (bash, sh extension), and the Public Domain Korn shell (pdksh, ksh extension). Most Linux systems is bash the default shell.

The Bourne Again Shell

Bourne Again shell (bash), as its name implies, is a Bourne shell extension. bash is fully backwards compatible with the Bourne shell and the Bourne shell, based on the increase and enhance the many features. bash also contains a lot of C and Korn shell in the benefits. bash has a very flexible and powerful programming interface, while there are very friendly user interface.

Why use bash instead of sh it? Bourne shell’s biggest drawback is that it handles user input area. In the Bourne shell, type the command will be in trouble, especially when you type a lot of similar commands. The bash command to prepare several input features to make it easier.


Orders filled (Command-Line Completion)
Usually you bash (or any other shell), enter the command you do not have to lose the whole shell command you want to be able to determine the type of command. For example, assume that the current working directory contains the following files and subdirectories:

News / bin / games / mail / samplefile test /
If you want to enter the test subdirectory, you will enter the following command:
cd test
This command is able to meet your needs, but the bash offers a slightly different way to accomplish the same thing. Because the only test is the current directory beginning with the letter t subdirectory, bash you can only enter the letter t after the judge what you do:
cd t
In that letter you type, the only possibility is to test. Want to help you bash the end of the command, then press the Tab key:

cd t
When you do later, bash will help you filled the command and displays on the screen. But before you press Enter the command is not executed, bash command will let you test whether you filled a real need. In short order the input like this when you may not see its value, even in very short order will simply slow the rate of input, but when you enter the command a little long, you will find this feature is how OK.
But when the directory has more than one file that starts with the letter t what happens when you do? Filled in when you have problems using the command, let us look at the following situation, the current directory has the following contents:

News / bin / mail / samplefile test / tools / working /
This directory now has two files beginning with the letter t. Assuming you still want to enter the test subdirectory, how to use the command filled it? If you did like the previous type:
cd t
bash will not know which directory you want to enter in the end, because the information given is not unique. If you do so, bash will beep to remind you do not have enough information to filled your order. Bash does not change after the beep enter the command, which will enable you to on the basis of the original input more information, in this case you only need to type an e and then press the Tab key, then bash it have enough information to complete your order: the
cd test
When you enter a command whenever you press the Tab key, bash will do our best to try to filled orders, it will not beep to remind you need more information. You need to type more characters and press Tab again, repeat this process until your desired command appears.

Wildcard
Another makes it easier to command input method is to use wildcards in the command. bash supports three wildcards:

*
Match any character and any number of characters

?
Match any single character

[...] Are included in brackets matches any single character

* Some like to use wildcard command padded. For example, suppose the current directory contains the following files:

News / bin / games / mail / samplefile test /

If you want to get into the test directory, you type cd test, or you want to use the command filled:

cd t

Now there is a third way to do the same thing. Because only one file with the letter t at the beginning, you can also use the * wildcard to enter the directory. Type the following command:

cd t *

* Matches any character and any number of characters, so the shell will replace the t * test (and pass the current directory the only files that match with the program). The current directory is only one file starting with the letter t, then it will be reliable. However, if the current directory has more than one file begins with the letter t, shell will try to meet the matching program into the first directory, this directory is based on the first alphabet sort directory, the directory is probably not what you might expect.

The wildcard * is a more practical use wildcard command you to perform multiple similar names in the file. For example, suppose the current directory contains the following files:

ch1.doc ch2.doc ch3.doc chimp config
mail / test / tools /

If you need to print all the extension is. Doc file, you can use like this

Leave a Reply