BASH Shell (I)-bash shell function Introduction

Source: Internet
Author: User

In the bash shell series, when talking about variables, we first talk about the functions and modifications of environment variables, and then continue to talk about the use of historical commands. Next, let's talk about the important concept of "data stream redirection", and finally the use of pipeline commands!

A bash shell Introduction

The core is used to manage the entire hardware.Communicate with the core through shell~

The shell we often mention is actually a narrow definition. In general, in Linux, the so-called shell refers to the bash text mode shell. However, a shell in the broad sense can also be a graphical interface control software such as KDE! Because it can also help us communicate with the kernel.

Which shell does Linux use? Check the/etc/shells file. At least the following shells can be used:

/Bin/sh (replaced by/bin/bash)
/Bin/bash (the shell preset in Linux)
/Bin/KSh (kornshell developed by at&t Bell lab. And compatible with Bash)
/Bin/tcsh (integrating C shell to provide more functions)
/Bin/CSH (replaced by/bin/tcsh)
/Bin/zsh (shell with more powerful functions developed based on KSh)

Which shell does my user get by default ?!

Remember the login action we mentioned in the first entry to Linux-logging in as text? When I log in, the system will give me a shell for me to work. The shell obtained by this login is recorded in the/etc/passwd file! What is the content of this file?

[Root @ Linux ~] # Cat/etc/passwd
Root: X: 0: 0: Root:/root:/bin/bash
Bin: X: 1: 1: Bin:/bin:/sbin/nologin
Daemon: X: 2: 2: daemon:/sbin/nologin
... (Omitted in the middle ).....

Introduction to bash shell

Chap1 Bash has the following advantages:

1) command compilation capability (similar to DoS doskey function ):

"Memory commands used !』 Press "up/down" in the Command column to find the previous command! Record files in your home directory. bash_history! ~ /. Bash_history records the commands that have been executed before the previous logon. The commands executed during this logon are saved in the temporary memory. After you successfully log out of the system, this command is recorded in memory. bash_history!

2) commands and file complementing functions:

[Tab] after the first word of a string of commands, the command is supplemented;
[Tab] after the second word of a string of commands, it is "file completion 』!

If I want to know how many commands can be executed in my environment? Enter two [Tab] [Tab] After the bash prompt character to output All executable commands.

3) command alias (alias) setting function:

Alias LM = 'LS-al'

4) Job control and foreground background control:

Resource management

5) powerful features of shell scripts:

In the DOS era, remember to write a bunch of commands together in the so-called "batch file? In Linux, shell scripts provides more powerful functions. It can write the continuous commands that you often need in your daily life into a file, this file can also be used for host detection through interactive discussion! The whole design is almost a small programming language! In the past, what needs to be written in a program language under DOS can be achieved through simple shell scripts in Linux.

6) Ten thousand characters!

For example, do you want to know how many files start with XT under/usr/x11r6/bin? Ls-L/usr/x11r6/bin/XT * can be found ~ In addition, there are other available characters, which can accelerate user operations.

Chap2 built-in command: Type

To facilitate shell operations, Bash has already "built in" many commands, such as CD and umask commands, so how do I know that this command is from an external command (referring to the commands provided by other non-bash suites) or built-in in Bash:

[Root @ Linux ~] # Type [-TPA] Name

Parameters:
: If no parameter is added, TYPE Displays whether the name is an external command or a bash built-in command!

-T: when the-t parameter is added, type will show the meaning of name with the following words:
File: indicates an external command;
Alias: indicates the name set for the command alias;
Builtin: indicates that this command is a built-in command function of bash;

-P: If the followed name is a command, the complete file name (external command) or built-in command is displayed;
-A: All commands with names are listed in the path defined by the PATH variable, including alias

Example 1: Check whether the LS command is built in bash?
[Root @ Linux ~] # Type LS
Ls is aliased to 'ls -- color = tty'
# List the main usage of the LS command without adding any parameters
[Root @ Linux ~] # Type-T LS
Alias
# The-t parameter only lists the main usage instructions of the LS command.
[Root @ Linux ~] # Type-A ls
Ls is aliased to 'ls -- color = tty'
Ls is/bin/ls
# Ls-related information found using all methods will be listed!

Example 2: What about CD?
[Root @ Linux ~] # Type CD
CD is a shell builtin

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.