Results 1 to 6 of 6

Thread: What is multiline > prompt in Bash?

  1. #1
    Join Date
    May 2007
    Beans
    71
    Distro
    Ubuntu 12.04 Precise Pangolin

    What is multiline > prompt in Bash?

    I am comfortable in Bash but one thing still baffles me...
    If I type just \ at a Bash prompt, the new line changes my prompt handle from the normal user@machine:~$ to just the greater than symbol >. This looks like:
    Code:
    user@machine:~$ \
    >
    Then hitting enter will keep this strange prompt going.
    Code:
    >
    >
    >
    like that.
    If I execute any other normal process it then goes away, reverting back to my normal prompt:
    Code:
    > ls
    (normal output of ls)
    user@machine:~$
    Question, what is this phenomenon and what is for?
    Last edited by Backharlow; February 7th, 2009 at 12:33 AM.

  2. #2
    Join Date
    Jun 2008
    Location
    UK
    Beans
    282
    Distro
    Xubuntu 16.04 Xenial Xerus

    Re: What is multiline > prompt in Bash?

    If you check the man page for bash you will find that there are four environment variables PS1, PS2, PS3 and PS4.

    PS1 is your normal prompt. PS2 is for multi-line commands, eg
    Code:
    $ for i in *
    > do
    > echo $i
    > done
    $
    PS3 is used for prompts with the select command, and PS4 is used for execution traces.

    In my .bashrc I tend to set PS1 and PS2 to the same thing except for the trailing $/>.

    Andrew

  3. #3
    Join Date
    Jun 2008
    Location
    California
    Beans
    2,271
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: What is multiline > prompt in Bash?

    Quote Originally Posted by apmcd47 View Post
    If you check the man page for bash you will find that there are four environment variables PS1, PS2, PS3 and PS4. PS1 is your normal prompt. PS2 is for multi-line commands, eg...
    Thanks apmcd47. I've encountered the same prompt and never understood its purpose.

  4. #4
    Join Date
    Jul 2008
    Beans
    1,491

    Re: What is multiline > prompt in Bash?

    It also enables you to echo multiline strings in the shell.
    Code:
    echo '
    line1
    line2
    done3
    '

  5. #5
    Join Date
    May 2008
    Beans
    Hidden!

    Re: What is multiline > prompt in Bash?

    The point is that you can split a command across more than one line.

    Oddly enough, I can't reproduce this. If I type \, press enter, and press enter again, I get back to my normal prompt.

  6. #6
    Join Date
    Sep 2006
    Beans
    2,914

    Re: What is multiline > prompt in Bash?

    Quote Originally Posted by Backharlow View Post
    I am comfortable in Bash but one thing still baffles me...
    If I type just \ at a Bash prompt, the new line changes my prompt handle from the normal user@machine:~$ to just the greater than symbol >. This looks like:
    Code:
    user@machine:~$ \
    >
    Then hitting enter will keep this strange prompt going.
    Code:
    >
    >
    >
    like that.
    If I execute any other normal process it then goes away, reverting back to my normal prompt:
    Code:
    > ls
    (normal output of ls)
    user@machine:~$
    Question, what is this phenomenon and what is for?
    the "\" just escapes the newline for you. ie, you are going to another line. just like when you write your commands in an editor. do not worry about ">".

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •