Linux Shell Basics-2

Source: Internet
Author: User

    • Pipe character
    • Fg
    • Bg
    • Sleep
    • Variable
      • Set
    • Defining variables
    • Variable classification
    • Cancel a variable
    • environment variable configuration file
Pipe character
管道命令操作符是:”|”,它仅能处理经由前面一个指令传出的正确输出信息,也就是 standard output 的信息,对于 stdandarderror 信息没有直接处理能力。然后,传递给下一个命令,作为标准的输入 standard input.

Attention:

1、管道命令只处理前一个命令正确输出,不处理错误输出2、管道命令右边命令,必须能够接收标准输入流命令才行。
Fg
fg命令用于将后台作业(在后台运行的或者在后台挂起的作业)放到前台终端运行。与bg命令一样,若后台任务中只有一个,则使用该命令时,可以省略任务号。在Linux系统中执行某些操作时候,有时需要将当前任务暂停调至后台,或有时须将后台暂停的任务重启开启并调至前台,这一序列的操作将会使用到 jobs、bg、和 fg 三个命令以及两个快捷键来完成。
Bg
bg命令用于将作业放到后台运行,使前台可以执行其他任务。该命令的运行效果与在指令后面添加符号&的效果是相同的,都是将其放到系统后台执行。

Attention:

实际上,使用bg命令与在指令后面添加符号"&"的效果是一样的。例如,使用&将find / -name password放到后台执行,输入如下命令:find / -name password &     #后台执行任务
Sleep
sleep命令暂停指定的时间
Variable

To view variables:

命令: env和echo、set

Instance:

# 用env查看系统变量env |grep "LANG"LANG=en_US.UTF-8# 当然,这里为了演示只是筛选出一个变量,其实env一般是用来查看所有变量,或者记不清楚变量名称时来查询的。# echo命令打印变量内容echo $HISTSIZE1000# 非全局自定义变量env查不到a=SGenv|grep "SG"# 将a变量声明成全局,再次用env查看export aenv |grep "SG"a=SG
Set
set命令作用主要是显示系统中已经存在的shell变量,以及设置shell变量的新变量值。
Defining variables
变量命名方式: "="两边不能有空格变量名称不能以数字起头变量值如果有空格、特殊字符,需加单引号或双引号
Variable classification
两种分类方式:系统变量 PATH、HOME、HOSTNAME、SHELL、HISTSIZE、USER等自定义变量 aa、bb等或者全局变量 所有程序都可调用程序变量 只能在给变量赋值当下程序可以使用

Instance:

# 利用bash命令进入一个子bash来验证全局变量和非全局变量quanju=‘I am global‘noqj=‘I am not global‘# 把quanju变量声明到全局export quanju# 进入子bash,用pstree查看下处在哪个bashbashpstree|grep ‘bash‘     |-login---bash     |-sshd---sshd---bash---bash-+-grep# 查看变量,只有全局变量quanju显示了内容,另外一个为空echo $quanju ; echo $noqjI am global# PS:# export a=aming,只能当前终端下全局  # 重新打开终端不管用,这些变量只保存在内存
Cancel a variable
unset 变量名称(取消掉变量值)
# unset了quanju,重新查看,quanju已经不存在了unset quanjuecho $quanju
environment variable configuration file
用户家目录下(针对该用户生效).bash_logout:logout的时候执行的命令.bashrc:配置alias.bash_profile:配置用户PATH.bash_history:记录history内容  /etc/目录下(全局)profile:配置PATH  用户环境变量,交互,登录才执行bashrc:配置PS1,PATH,UMASK等   用户不用登录,执行shell就生效重新加载配置文件命令source 配置文件. 配置文件

Instance:

## 修改PS1变量范例## \u代表user,\h代表hostname,\W代表路径最后一层[[email protected] etc]# echo $PS1[\[email protected]\h \W]\$# 修改PS1变量最后一段为绝对路径,查看区别    # \w代表使用绝对路径[[email protected] etc]# PS1=‘[\[email protected]\h \w]\$ ‘[[email protected] /etc]## 用双引号的话必须转义掉$[[email protected] /etc]# PS1="[\[email protected]\h \w]\\$ "[[email protected] /etc]#

Linux Shell Basics-2

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.