0

I've been a pretty long-term user of Linux, Solaris and bash but have never found a solution to this problem. This must be pretty common so curious if others found a better way to do this.

I am doing some testing of a REST API interface using bash. I use curl commands then continuation characters like to separate out a new line for each HTTP header. I store my notes in a text file so that I can copy/paste into SecureCRT or any SSH client quickly.

====NOTE FORMAT====

$ curl xxxxxx \
-H "X-Header1: test" \
-H "X-Header2: test2" \ 
xxxxx

Above I can just copy and paste in to SSH and hit return and it runs the command. If I then modify something and want to paste back out of the SSH client back into my notes, I get the continuation characters, because this is how bash interprets these:

=====IN TERMINAL=====

$ echo hello \
> world
hello world

See how in the terminal we have "> " because this is how bash prompts for the next line and so forth. If you have a bunch of commands that you want to copy/paste in and out all the time with 12 different headers, it's a lot of work to clean up by removing the "> " from each line.

I've googled and found some discussion on similar things like on https://stackoverflow.com/questions/7316107/bash-continuation-lines

I hoped that in bash, I could change the continuation prompt, which I would remove the prompt by changing an environment variable, much like the PS1 variable allows you to change the command prompt. I haven't found anything in this.

In bash history, you don't see the continuation characters as it removes all of these onto a single line (very difficult to read and edit).

So, there might be some other options here:

  1. Find a configuration to change the continuation prompt to solve this, or find a way to do it with an environment variable.
  2. Use another shell which doesn't use this method or allows it to be modified. I've pretty much only used bash, little bit of csh.
  3. Do something like repeat the command entered and use sed or something to remove the > characters or echo the .bash_history entry and add in newline characters at certain points to make it readable.

Before I go find another way, anyone know if it's even possible to do what I'm asking with bash?

Also, I get that the continuation prompt is there for a reason otherwise it could just be a blank line - I'd be looking at a way to change an environment variable to switch back and forth, or something like that.

3

My tests indicate this variable is relevant:

PS2
The secondary prompt string. The default value is >. PS2 is expanded in the same way as PS1 before being displayed.

(source)

Solutions (pick one):

unset PS2
          # or
PS2=''

Note you can export a variable containing an empty string but you cannot export a variable that is not set. Use the latter solution if you want to export PS2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.