in reply to How do I keep the command line from eating the backslashes?

assuming bash or similar shell (unknown on windows)
# \\ escapes the slash # \" escapes the quote # so \\\" escapes a single slash and a quote foo.pl -bar=\\\"donteatem\\\"
perl should get -bar=\"donteatem\"

Replies are listed 'Best First'.
Re^2: How do I keep the command line from eating the backslashes?
by Anonymous Monk on Feb 11, 2005 at 21:27 UTC
    Ahh... I'd love to be able to do that... But what if I cannot control the input? I'm reading input destined for another program, and I (most unfortunately) don't have control of what's generating the commandline.

    So, I'm always going to get \" instead of \\"
      Two thoughts.

      First, it's the shell that's eating the quotes and backslashes. If you change the shell to a program of your own, you can process these characters however you want. Many programs use the SHELL environment variable to select the shell to run, so changing that might help.

      Second, in order for arguments to have gotten through the shell, they must have been quoted properly. quotemeta can quote them properly, even if it's not the same way they were originally quoted.