You didn't pass a Line Feed. You passed a Backslash and a Latin Small Letter N

To Pass a Line Feed, you can use

# tcsh -string 'foo\ bar'
or
# POSIX sh, ksh, bash, dash -string 'foo bar'
or
# POSIX sh, ksh, bash, dash -string "$( printf 'foo\nbar' )"
or
# bash -string $'foo\nbar'

Is there a way to have the '\n' interpreted as an actual newline character by the perl script?

s/\\n/\n/g

But what if someone actually wants to provide the two characters \n? It's up to you to define your language and write a parser and interpreter for it.

And don't forget that scripts that call your program would need an escaping function to provide user input to your program.

It's far simpler to simply provide the correct string, which is why I led with that. Is there a way to have the '\n' interpreted as an actual newline character by the perl script?


In reply to Re: passing newline in string argument by ikegami
in thread passing newline in string argument by Special_K

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.