Shell issues variable execution when the command is executed [multiple commands are executed simultaneously]

Source: Internet
Author: User

Shell writes a shell script for the variable when the command is executed [multiple commands are executed at the same time]. The script needs to run the variable as a shell command. There are many common methods, such: '$ {var}' executes the variable content as a shell command line $ ($ {var }) when the shell command executes $ {var}, the variable content is used as the shell command to execute [this method is not recommended]. However, only one command can be run in these three methods, if the command is of the following type, there will be a problem: VAR1 = 'CD/home; echo "hello "; echo "good" 'var2 = 'CD/home & echo "hello" & echo "good" 'at this time, $ ($ {VAR1}) will find no output, by tracking the command execution process, it is found that the shell will automatically run; & use ''for restrictions. To solve this problem, I found a lot of information and there is no good solution, this method is usually used in the crontab command, and the execution is normal. You can view the crontab Resource Finally, the awk system function is used to solve the problem. Solution: VAR1 = 'CD/home; echo "hello "; echo "good" 'var2 = 'CD/home & echo "hello" & echo "good" 'echo $ {VAR1} | awk' {run = $0; system (run)} 'echo $ {VAR2} | awk '{run = $0; system (run)}' the execution result is correct hello good

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.