The question you have asked only concerns how the shell interprets its input and passes it along to other programs. It has nothing to do with Perl, per se.
You should just be able to put this in a script:
foo '$x;
$y;'
The argument given to the command will have a newline in the same place as it does in the script itself. You may need to take care to save such a script in such a way that it ends with Unix-style (LF-only) line breaks, otherwise you might get a CR+LF (DOS/Windows line breaks) or just CR (old Mac-style lineb reaks). You can also do this at an interactive prompt, but you will see a continuation prompt before the second and any subsequent lines:
$ foo '$x;
> $y;'
In bash, you can also use the $''
quoting syntax to encode a newline character like this:
foo $'$x;\n$y;'
The argument passed to the program will be treated in a manner similar to an ANSI C string. If you want an actual backslash in the string you will have to escape it as \\
, instead.
So, if you really want the literal-string quoting that single quotes give you, you should probably stick with an embedded newline so that you do not have to worry about extra escaping.
2
Duplicate of http://superuser.com/questions/123467/insert-newline-in-perl-e-statement
– Josh K – 2010-03-25T04:40:31.473please don't double-post. you can edit your earlier question to add information if you need to. – quack quixote – 2010-03-25T04:44:16.207
this is a slightly different question to http://superuser.com/questions/123467/insert-newline-in-perl-e-statement (which has been answered) Please don't close.
– Don Ch – 2010-03-25T05:26:11.863ok, yes, i see a miniscule difference. but there's an answer on your other question (that i just expanded) that answers this question too. (granted, not as well as Chris's answer below...) since they are so closely related (they have practically the same title), i still think they should be in one post. – quack quixote – 2010-03-25T05:34:26.960