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}) and considers the variable content as a shell... 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" 'run $ ($ {VAR1}) no output is found. by tracking the command execution process, it is found that the shell automatically runs; & use ''for restrictions. to solve this problem, I checked a lot of information, there is no good solution. Generally, our crontab command will write this method, and there is no problem in executing it. By viewing crontab information, we can find the system function used, so we finally use the awk system function 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
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.