What does 'bash -c' do?

LinuxBash

Linux Problem Overview


I followed the following tutorial: 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.

Linux Solutions


Solution 1 - Linux

Quoting from 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.

The command quoted by you would append the text in heredoc (i.e. the text in VirtualHost tag) to the file /etc/apache2/sites-available/magento-store.com.

Solution 2 - Linux

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.

Solution 3 - Linux

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

Quote:

-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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiongiannisapiView Question on Stackoverflow
Solution 1 - LinuxdevnullView Answer on Stackoverflow
Solution 2 - LinuxlightandlightView Answer on Stackoverflow
Solution 3 - LinuxsailingthomsView Answer on Stackoverflow