2

I'm writing a small perl wrapper to setup environment variables, etc., then invoke a command by the same name.

./foo.pl -a one -b two -c "1 2 3" -d done

When I output @ARGV, the "" around 1 2 3 have been stripped. Does someone know how to have perl keep these quotes?

2
  • 1
    Cannot be done: the shell strips them explicitly before sending the arguments to perl: gnu.org/software/bash/manual/bash.html#Quote-Removal Commented Aug 9, 2018 at 21:32
  • 1
    What problems are you having in perl with a string not having literal quotes in it? If you provide some details, I'd be happy to help. Commented Aug 9, 2018 at 21:33

2 Answers 2

1

It's not that perl doesn't keep the quotes, perl never gets them. The quotes are just one way to prevent the shell from splitting the text into multiple arguments. The same effect can be achieved with backslash:

./foo.pl -a one -b two -c 1\ 2\ 3 -d done

The effect is on both cases a string of 1, space, 2, space, 3. You can also put quotes around the other arguments that don't contain spaces, the quotes are still not part of the arguments passed to the program.

If you want to pass arguments to the shell, you can just put quotes around all. Or you can put a backslash before every special shell character.

0

Simplistically, add hard quotes:

./foo.pl -a one -b two -c '"1 2 3"' -d done

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.