The fifth chapter of the Linux command line and Shell script programming Encyclopedia understands the shell

Source: Internet
Author: User
Tags aliases


1. cat/etc/passwd

You can view each user's own default shell program.

2. The default interactive shell starts when the user logs in to a Virtual Console terminal.

But there is another default shell is/bin/sh, which acts as the default shell for those shell scripts that need to be used at startup

Ls-l/bin/sh for viewing

The default system shell (Dash shell) and the default interactive shell (bash shell) are not the same in Ubuntu's release.

You can start the dash shell directly with dash.

Exit exits

5.2 Shell's parent-child relationship

A shell can create another shell (a child shell).

Ps-f a look.

The bash shell is a process (a running program).

Entering bash will create a child shell.  Exit exits. Ps-f--forest. You can show nested structures between processes.

5.2.1 Process List

$ pwd; ls Pwd CD/; Echo $BASH _subshell

This allows the command to execute sequentially. This is performed in the current shell.

$ (PWD; LS; echo $BASH _subshell;)//This is performed in a child shell.

() can also be nested, such as PWD; (PWD; (LS; cd/home))

echo $BASH _subshell returns 0, indicating that there is no child shell.

$sleep 300&//Background Run command,& is to put the command into the background mode

Jobs can view background job information

You can also do this by placing the process list in the background.

$ (sleep 2; echo $BASH _subshell; sleep 2;) &

Co-process: You can do two things at the same time, it generates a child shell in the background, and executes commands in this child shell.

Use the Coproc command for co-processing:

$ Coproc Sleep 10

You can also do this:

$coproc MyJob {sleep 10;} That's the equivalent of giving sleep 10 a name. Pay attention to the few spaces

5.3 Understanding the Shell's built-in commands

1. External command: Also known as File System command, there are commands outside of the bash shell. Not part of the shell program.

Typically located in/bin/usr/bin/sbin/usr/sbin.

A child process is created when an external command executes. This operation is called derivation (forking).

For example, PS is an external command, you can use the which and type command to find it

$which PS

$ type-a PS

$ ls-l/bin/ps

2. Built-in command: No sub-process to execute, and Shell is one, do not need to use external program files to run.

(1) such as exit and CD are built-in commands

$type exit

$type CD

Some commands have multiple implementations, such as PWD and Echo, which have both external and built-in commands

#type-a Echo

The which only displays external command files.

Type-a shows two implementations of each command.

Tip: For multiple implementations of the command, the default execution is built-in, if you want to execute an external command can specify the corresponding file is good.

Like what

$PWD//Execution of internal commands

$/BIN/PWD//Execution of EXTERNAL commands

(2) View the command of history execution

$ history//This is built-in command

You can see the previously executed command, preceded by a number that represents the command number. Like, 38.

$!38//indicates execution of 38th order

(3) $!! This is the command that executes the last input.

(4) Command aliases

Alias is also a built-in command

$alias-P//view the currently available aliases

To create your own commands

$alias xcyls= ' Ls-al '

An alias is only valid in the shell process that it is defined in. Changes under ~/.BASHRC can work for all shells

Shell Child shell process sub-processes are affected by environment variables.

The fifth chapter of the Linux command line and Shell script programming Encyclopedia understands the shell

Related Article

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: 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.