in reply to passing newline in string argument

This seems like a shell issue instead of a Perl question, because it appears the shell isn't interpreting \n as a newline. In other words, Perl is getting passed the literal 8-character string "foo\\nbar" from the shell.

I'm unfortunately not well-versed in tcsh so the "best" solution I've found so far is:

#!/bin/tcsh /home/perl_scripts/pass_newline_as_text.pl \ -string "foo\ bar"

I would typically recommend against working around this in Perl, because if you start supporting "\\n" to "\n" translation in Perl, then the question is which escape codes do you want or need to support, and it quickly becomes overly complicated - see my three posts in this thread: Can't get \n or other character/translation escapes to interpolate if originally read from a data file

Replies are listed 'Best First'.
Re^2: passing newline in string argument
by ysth (Canon) on Aug 01, 2025 at 21:43 UTC
    "`/bin/echo -e 'foo\nbar'`" should work, as it does in bash, but I can't get it to :(

      Try

      "`/bin/echo -e \"foo\nbar\"`"

        Nope.

        tribble:~> perl -E'say $ARGV[0]' "`/bin/echo -e 'foo\nbar'`" foo
        tribble:~> perl -E'say $ARGV[0]' "`/bin/echo -e \"foo\nbar\"`" Unmatched '`'.

        I stopped using tcsh 20 years ago because it was a horrible shell for programming.