I use PHP exec()
to start a process in Bash that has $$
in its commandline. When using PHP though, PHP itself seems to take the variable $$
instead of letting Bash use it in the script.
Does PHP use this variable? Assuming so, how do I preserve it for the Bash script?
Example: exec('echo $$')
performs echo 1538
in Bash, not echo $$
, since PHP seems to have taken the variable $$.
Php would not 'take' the $$
value, since it's inside a single-quoted string.
It's bash converting it to the PID of the bash process handling your echo command.
If you want to literally output two $
via the echo command, you'll have to escape them:
exec('echo \\$\\$');
followup:
marc@panic:~$ bash
marc@panic:~$ echo $$
31285
marc@panic:~$ php -a
Interactive shell
php > echo exec('echo $$');
31339
php > echo exec('echo \\$\\$');
$$
followup 2:
marc@panic:~$ cat pid
#!/bin/bash
echo $$
marc@panic:~$ ./pid <--new shell started to execute script
31651
marc@panic:~$ . pid <---script executed within context of current shell
31550
marc@panic:~$ echo $$
31550
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With