Child shell Test

Source: Internet
Author: User

Pstree
echo $$//Current process PID
Echo $PPID//Parent process ID
Sub-process test:
New file:
[Email protected]]~ # VI bashpid.sh
#!/bin/bash
Echo $BASHPID

//测试[[email protected]]~ # echo $BASHPID  //当前shell    6136  //结果[[email protected]]~ # bash bashpid.sh    6550  //结果[[email protected]]~ # source ./bashpid.sh  //不开启shell子进程    6136  //结果与当前shell结果一样[[email protected]]~ # ./bashpid.sh  //开启子shell运行脚本    6555[[email protected]]~ # (echo $BASHPID)   //小括号表示进入子shell执行命令    6558[[email protected]]~ # { echo $BASHPID; }  //花括号表示在当前shell执行命令    6136  //结果与当前shell结果一样

Variables can only be passed down, inherited, not uploaded, inherited
#name =parent; (echo "1: $name"; Name=son;echo "2: $name"); echo "3: $name"//parenthesis () Open the child shell to enter the child shell
1:parent
2:son
3:parent
Curly braces {} Do not open sub-shell,shell programming may be used.

Name=parent; {echo "1: $name"; Name=son;echo "2: $name";}; echo "3: $name"//curly braces do not enter the child shell
    1:parent    2:son    3:son

Child shell Test

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.