Linux 'bash -c' 有什么作用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20858381/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does 'bash -c' do?
提问by giannisapi
I followed the following tutorial: http://davidtsadler.com/archives/2012/06/03/how-to-install-magento-on-ubuntu/
我遵循以下教程:http: //davidtsadler.com/archives/2012/06/03/how-to-install-magento-on-ubuntu/
At some point it told me to execute the following command:
在某些时候它告诉我执行以下命令:
sudo bash -c "cat >> /etc/apache2/sites-available/magento-store.com <<EOF
<VirtualHost *:80>
ServerName localhost.magento-store.com
ServerAlias www.localhost.magento-store.com
DocumentRoot /home/dev/public_html/magento-store.com/public
LogLevel warn
ErrorLog /home/dev/public_html/magento-store.com/log/error.log
CustomLog /home/dev/public_html/magento-store.com/log/access.log combined
</VirtualHost>
EOF"
What did this command do, and how I can cancel that?
这个命令做了什么,我如何取消它?
I restarted the computer, and it seems that it is still running. I looked in .bashrc
and .profile
, but I did not find it inside.
我重新启动了计算机,它似乎仍在运行。我看着.bashrc
和.profile
,但我没有里面找到它。
采纳答案by devnull
Quoting from man bash
:
引自man bash
:
-c string If the -c option is present, then commands are read from
string. If there are arguments after the string, they are
assigned to the positional parameters, starting with -c string
If the -c option is present, then commands are read from string.
If there are arguments after the string, they are assigned to the positional
parameters, starting with ##代码##.
.
The command quoted by you would appendthe text in heredoc (i.e. the text in VirtualHost
tag) to the file /etc/apache2/sites-available/magento-store.com
.
您引用的命令会将heredoc 中的文本(即标签中的文本)附加VirtualHost
到文件中/etc/apache2/sites-available/magento-store.com
。
回答by lightandlight
The manual page for Bash(e.g. man bash
) says that the -c
option executes the commands from a string; i.e. everything inside the quotes.
Bash 的手册页(例如man bash
)说该-c
选项从字符串执行命令;即引号内的所有内容。