I am generating a shell script from within a script and it needs root permissions so I use
sudo bash -c "echo 'Hello There!' > '/var/www/cgi-bin/php-cgi-5.3.8'"
I get an error if I try to output the shebang line and I not sure how to escape it — like i do with other variables.
sudo bash -c "echo '#!/bin/bash
version=\"5.3.8\"
export PHPRC=/etc/php/phpfarm/inst/php-\${version}/lib/php.ini
export PHP_FCGI_CHILDREN=3
export PHP_FCGI_MAX_REQUESTS=5000
exec /etc/php/phpfarm/inst/php-\${version}/bin/php-cgi' > '/var/www/cgi-bin/php-cgi-5.3.8'"
Where am I going wrong here?
!is looking for a command beginning with'in your bash_history. You should have the ‘!’ unquoted and escape it with a backslash. You may as well take the#out of quotes and escape it too, since a\is shorter than two quotes.