| Bob Showalter 2006-01-25, 6:57 pm |
| Michael Weber wrote:
> Greetings!
>
> I am not completely understanding how perl parses quotes.
>
> Here is the line I want to execute:
>
> exec "$command $cmd_msg";
>
> The variable $command is an executable shell script "test.sh"
>
> The problem comes in the $cmd_msg variable.
>
> This contains a line from my log file:
>
> Nov 13 11:54:31 fw-3 sshd(pam_unix)[19906]: authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=82-148-208-172.fiber.unet.nl
>
> The shell script blow up on the parenthesis:
>
> sh: -c: line 0: syntax error near unexpected token `('
>
> How can I quote the exec line above so what gets passed to /bin/sh is the log file line contained in double quotes?
Simplistic, but possibly risky:
exec qq[$command "$cmd_msg"];
Much better, IMO:
exec "$command \Q$cmd_msg";
Or even better, bypass the shell by using the list form of exec():
exec $command, $cmd_msg;
|