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

  • SEARCH
  • Home
  • 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 9301277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:58:41+00:00 2026-06-18T22:58:41+00:00

I am calling a python script, parse_input.py from bash parse_input.py takes a command line

  • 0

I am calling a python script, parse_input.py from bash

parse_input.py takes a command line argument that has many '\n' characters in it.

Example input:

$ python parse_input.py "1\n2\n"

import sys
import pdb

if __name__ == "__main__":

    assert(len(sys.argv) == 2)

    data =  sys.argv[1]
    pdb.set_trace()
    print data

I can see on pdb that `data = "1\\n2\\n" whereas I want data="1\n2\n"

I saw similar behavior with just \ (without \n) which gets replaced by \\

How to remove the extra \ ?

I don’t want the script to deal with the extra \ as
the same input can also be received from a file.

bash version: GNU bash, version 4.2.24(1)-release (i686-pc-linux-gnu)

python version : 2.7.3

  • 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-06-18T22:58:43+00:00Added an answer on June 18, 2026 at 10:58 pm

    Bash doesn’t interpret escape characters in regular single and double-quoted strings. To get it to interpret (some) escape characters, you can use $'...':

       Words of the form $'string' are treated specially.  The word expands to
       string, with backslash-escaped characters replaced as specified by  the
       ANSI  C  standard.  Backslash escape sequences, if present, are decoded
       as follows:
              \a     alert (bell)
              \b     backspace
              \e     an escape character
              \f     form feed
              \n     new line
              \r     carriage return
              \t     horizontal tab
              \v     vertical tab
              \\     backslash
              \'     single quote
              \nnn   the eight-bit character whose value is  the  octal  value
                     nnn (one to three digits)
              \xHH   the  eight-bit  character  whose value is the hexadecimal
                     value HH (one or two hex digits)
              \cx    a control-x character
    
       The expanded result is single-quoted, as if the  dollar  sign  had  not
       been present.
    

    i.e.

    $ python parse_input.py $'1\n2\n'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am calling a python script with the following command line: myscript.py --myopt=[(5.,5.),(-5.,-5.)] The
I am calling a python script from PHP. The python program has to return
I'm calling a python script from the below one using subprocess. From the command
I have a python script that has to launch a shell command for every
I have a Python script that reads a file containing a command line invocation
I am calling a python script from within a shell script. The python script
I have a Python script script.py that has been defined as executable and which
I use exec function calling python script from PHP script. Python writes to standard
I am writing a Python command line program. There is a main Python script
I am calling a python script through a bash wrapper, but I'm having trouble

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.