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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:43:55  来源:igfitidea点击:

What does 'bash -c' do?

linuxbash

提问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 .bashrcand .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 VirtualHosttag) 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 -coption executes the commands from a string; i.e. everything inside the quotes.

Bash 的手册页(例如man bash)说该-c选项从字符串执行命令;即引号内的所有内容。

回答by sailingthoms

Check out the man pages, either on your machine or on the Internet, like this one.

查看您的机器上或 Internet 上的手册页,例如这个

Quote:

引用:

##代码##