Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Sub-shell test

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Pstree

Echo $$/ / current process pid

Echo $PPID / / parent process id

Child process testing:

New files:

[world@localhost] ~ # vi bashpid.sh

#! / bin/bash

Echo $BASHPID

/ / Test [world@localhost] ~ # echo $BASHPID / / current shell 6136 / / result [world@localhost] ~ # bash bashpid.sh 6550 / / result [world@localhost] ~ # source. / bashpid.sh / / do not start the shell sub-process 6136 / / the result is the same as the current shell result [world@localhost] ~ #. / bashpid.sh / / start the sub-shell run script 6555 [world@localhost] ~ # (echo $BASHPID) / / parentheses indicate that the entry child shell executes the command 6558 [world@localhost] ~ # {echo $BASHPID } / / curly braces indicate that the result of executing the command 6136 / / in the current shell is the same as the current shell result

Variables can only be uploaded and inherited, but not uploaded or inherited.

# name=parent; (echo "1:$name"; name=son;echo "2:$name"); echo "3:$name" / / parenthesis () opening child shell indicates the entry child shell

1:parent

2:son

3:parent

Curly braces {} do not open child shell,shell may be used in programming.

# 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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report