'bash -c'做什么?

gia*_*api 45 linux bash

我按照以下教程:http://davidtsadler.com/archives/2012/06/03/how-to-install-magento-on-ubuntu/

在某些时候它告诉我执行以下命令:

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"
Run Code Online (Sandbox Code Playgroud)

这个命令做了什么,以及如何取消它?

我重新启动计算机,似乎它仍在运行.我看着.bashrc.profile,但我没有里面找到它.

dev*_*ull 46

引用自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 $0.
Run Code Online (Sandbox Code Playgroud)

您引用的命令会将heredoc中的文本(即标记中的文本)附加VirtualHost到文件中/etc/apache2/sites-available/magento-store.com.

  • @ tjt263实际上,在这种情况下不使用-c会给你几个小时的调试试图以各种方式逃避各种引号,而事情仍然无效. (10认同)
  • 没有`-c`会有什么不同? (6认同)
  • @Christian此行为未记录,也与实际行为不符:https://i.imgur.com/ZeFAkDf.png (6认同)
  • 还要注意,从```bash -c```调用的命令将被强制为单线程.例如:```"bash -c'ffmpeg -threads 4 -i input.mov output.mp4'"```将调用ffmpeg但它只能使用一个核心,即使你指定了"threads"参数 (2认同)
  • @Christian为什么?这似乎很不合理. (2认同)
  • @NándorElődFekete 不知道为什么会这样,当我现在尝试时也发生了同样的情况。但是,当我从 bash 运行它时,会出现完全相同的结果:https://i.imgur.com/zqZQVPU.png。奇怪的是,看起来 ffmpeg 完全忽略了“-threads 4”参数。 (2认同)

lig*_*ght 11

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