Old boy Education Day-2017-04-25: How to produce a child shell?

Source: Internet
Author: User

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?

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.