1. execute a shell scriptin the parent Shell to produce a child shell
test Environment:
Define a variable and output
[[email protected] ~]$ Str=123[[email protected] ~]$ echo $STR 123
write a test script and execute
[
[email protected] ~]$ cat Test.sh#!/bin/bashecho $STR [[email protected] ~]$./test.sh [[email protected] ~]$ export str[[e Mail protected] ~]$./test.sh123
A child shell cannot directly use a variable defined in the parent shell, and export is promoted to an environment variable
2. Execute a command in theparent Shell , add & at the end of the command to produce a child shell
[Email protected] ~]$ str=123; Str=abc[[email protected] ~]$ echo $STRabc [[email protected] ~]$ str=123; STR=ABC&[1] 16467[[email protected] ~]$ echo $STR 123[1]+ done STR=ABC
Define a variable Str Assignment 123, re-assignment ABC, the value of the result variable str is ABC, when the second assignment is added to the end of the &, the variable str value does not change, indicating that the second assignment is not in the current shell, it opens a child shell.
3. Use () to produce a child shell
[Email protected] ~]$ str=123&& (STR=ABC) && echo $STR 123
with the above case, the variable assignment in the () cannot modify the value of the previous variable, and also produces the child shell
4. execute a command with a pipeline in the parent shell
[[Email protected] ~] $STR =123| Str=456;echo $STR 123
print variables in a child shell
[Email protected] ~]$ str=123| {Str=456;echo $STR;} 55W
today is a day to accompany everyone's first day, look forward to your progress.
For questions and answers, please leave a comment in the blog comments section.
Index of the topic of the previous period
http://lidao.blog.51cto.com/3388056/1914205
This article is from the "Lee blog" blog, make sure to keep this source http://lidao.blog.51cto.com/3388056/1919355
Old boy Education Day-2017-04-25: How to produce a child shell?