Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7435411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:04:10+00:00 2026-05-29T10:04:10+00:00

For the following piping in a Bash script : Bash command | perl -ne

  • 0

For the following piping in a Bash script :

Bash command | perl -ne 'single line perl command' | Another Bash command

The Perl command could only be single line. How about if I want to write more complex multi-line Perl commands. Could I use multiple “-e” options for each perl command line, such as :

perl -n -e 'command line 1' -e 'command line 2' -e 'command line 3'

Or could I use a “Here Document” for the multi-line Perl codes (the perl options, such as “-n”, should still be able to be specified in such case.) ?

If “Here Document” could be used, could anyone illustrate how to use it with an example.

Thanks in advance for any suggestion.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:04:10+00:00Added an answer on May 29, 2026 at 10:04 am

    If your Perl script is simply too long to be controllable on a single line (with semi-colons separating Perl statements), then bash is quite happy to extend your single quoted argument across as many lines as you need:

    Bash-command |
    perl -ne 'print something_here;
              do { something_else } while (0);
              generally("avoid single quotes in your Perl!");
              say q{Here is single-quoted content in Perl};
             ' |
    Another-Bash-Command
    

    Also the ‘perldoc perlrun’ manual says:

    -e commandline

    may be used to enter one line of program. If -e is given, Perl will not look for a filename in the argument list. Multiple -e commands may be given to build up a multi-line script. Make sure to use semicolons where you would in a normal program.

    -E commandline

    behaves just like -e, except that it implicitly enables all optional features (in the main compilation unit).

    So you could also do:

    Bash-command |
    perl -n -e 'print something_here;' \
            -e 'do { something_else } while (0);' \
            -e 'generally("avoid single quotes in your Perl!");' \
            -e 'say q{Here is single-quoted content in Perl};' |
    Another-Bash-Command
    

    If the script gets bigger than, say, 20 lines (somewhere between 10 and 50, somewhat according to choice), then it is probably time to separate the Perl script into its own file and run that instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following Izb's question about Best binary XML format for JavaME , I'm looking for
Following on from this question what would be the best way to write a
I am trying to program a email piping php script that would take an
Following is the Script i am working that will indicate the Feature Detection for
Is there a more concise/standard idiom (e.g., a JDK method) for piping an input
I am learning about piping and shell in a Systems class. I'm messing around
My question is relative to this post: Piping data on Windows command prompt I
I use Terminal in Mac with the following command: df -lak | grep File||disk02
I have the following rows in a file that I want to get the
I'm trying to run the following command using the 'exec' task in Ant: ls

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.