Shell Foundation (middle)

Source: Internet
Author: User

Pipe symbol, Job control


1. Pipe symbol | : Outputs a command to the following command execution

[[email protected] ~]# ls111  1.txt   2_hard.txt  2.txt.bak.bak  4.txt              apr-1.4.5123  1.txt~  2_soft.txt  3.txt          anaconda-ks.cfg.1  apr-1.4.5.tar.gz[[email protected] ~]# ls | wc -l12

2.ctrl+z: Pause execution of the command:

[[email protected] ~]# vim 1.txt[1]+  已停止               vim 1.txt

3. Use command FG to continue execution of the paused command: Put the command to the foreground

[[email protected] ~]# fgvim 1.txt

4.jobs command: Lists the stopped commands to

[[email protected] ~]# jobs[1]-  已停止               vim aa.txt[2]+  已停止               vim 1.txt

5.bg: Move the command to the background to continue running
6.sleep time: How long is it suspended?
7. Add & to the command, and put the command directly in the background to execute.

Shell variables


1.ENV: View System Variables

[[email protected] ~]# envXDG_SESSION_ID=1HOSTNAME=weix-01SELINUX_ROLE_REQUESTED=TERM=xtermSHELL=/bin/bashHISTSIZE=1000SSH_CLIENT=192.168.127.1 53879 22SELINUX_USE_CURRENT_RANGE=SSH_TTY=/dev/pts/0USER=root

The 2.set command can view system variables as well as user-defined variables:

[[email protected] ~]# setBASH=/bin/bashBASHOPTS=checkwinsize:cmdhist:expand_aliases:extquote:force_fignore:histappend:hostcomplete:interactive_comments:login_shell:progcomp:promptvars:sourcepathBASH_ALIASES=()BASH_ARGC=()BASH_ARGV=()BASH_CMDS=()BASH_LINENO=()BASH_SOURCE=()BASH_VERSINFO=([0]="4" [1]="2" [2]="46" [3]="2" [4]="release" [5]="x86_64-redhat-linux-gnu")BASH_VERSION=‘4.2.46(2)-release‘COLUMNS=80DIRSTACK=()EUID=0GROUPS=()

3. Variable naming rules: Alphanumeric underline, the first cannot be a number

[[email protected] ~]# a1=2[[email protected] ~]# echo $a12[[email protected] ~]# a_1=3[[email protected] ~]# echo $a_13[[email protected] ~]# _a1=4[[email protected] ~]# echo $_a14[[email protected] ~]# 1aa=5-bash: 1aa=5: 未找到命令

4. When the variable value has a special symbol, it needs to be expanded with single quotation marks.

[[email protected] ~]# a=a b c-bash: b: 未找到命令[[email protected] ~]# a=‘a b c‘

Double quotes may not display correctly:

[[email protected] ~]# a="a$bc"[[email protected] ~]# echo $aa[[email protected] ~]# a=‘a$bc‘[[email protected] ~]# echo $aa$bc

5. Variable overlay: Multiple variable overlays can be caused by double quotation marks

[[email protected] ~]# a=1[[email protected] ~]# b=2[[email protected] ~]# echo $a$b12[[email protected] ~]# a=‘a$bc‘[[email protected] ~]# echo $a$ba$bc2[[email protected] ~]# c="a$bc"[[email protected] ~]# c="a$b"c[[email protected] ~]# echo $ca2c

6. Define variables as local variables directly on one terminal, not valid on other terminals
7. Define global variables: export, for a shell below the sshd in a backward-compatible global, cannot upward

[[email protected] ~]# export weix=linux[[email protected] ~]# echo $weixlinux[[email protected] ~]# bash[[email protected] ~]# echo $weixlinux

8.pstree: Can see under which bash

[[email protected] ~]# pstreesystemd─┬─NetworkManager───2*[{NetworkManager}]        ├─VGAuthService        ├─agetty        ├─auditd───{auditd}        ├─chronyd        ├─crond        ├─dbus-daemon───{dbus-daemon}        ├─firewalld───{firewalld}        ├─lvmetad        ├─master─┬─pickup        │        └─qmgr        ├─polkitd───5*[{polkitd}]        ├─rsyslogd───2*[{rsyslogd}]        ├─sshd───sshd───bash───bash───pstree        ├─systemd-journal        ├─systemd-logind        ├─systemd-udevd        ├─tuned───4*[{tuned}]        └─vmtoolsd───{vmtoolsd}

9. Cancel Assignment: unset

[[email protected] ~]# echo $weixlinux[[email protected] ~]# unset weix[[email protected] ~]# echo $weix
environment variable configuration file


1.profile: User login is automatically loaded
2.BASHRC: Execute shell script to load automatically without login
3.bash-logout: Defines what needs to be done when a user exits

    1. PS1: Changing the display
      [[email protected] ~]# PS1=‘[\[email protected]\h \w]\$‘[[email protected] ~]#ls111    1.txt~      2.txt.bak.bak  aa.txt             apr-1.4.5.tar.gz123    2_hard.txt  3.txt          anaconda-ks.cfg.11.txt  2_soft.txt  4.txt          apr-1.4.5[[email protected] ~]#cd /etc/Display all 186 possibilities? (y or n)[[email protected] ~]#cd /etc/                    [[email protected] /etc]#cd /root/123[[email protected] ~/123]#PS1=‘[\[email protected]\h \W]\$‘            #大写W,显示相对路径[[email protected] 123]#cd                            #小写w显示绝对路径

Shell Foundation (middle)

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