Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15
Well I have had a google about, and have read man-bash > PS1 & man-bash > PROMPTING... but I still don't geddit! My preset bash prompt is this: Code: stephen@linux-ahy5:~> ...
  1. #1
    Just Joined!
    Join Date
    Feb 2009
    Posts
    12

    Unhappy PS1 bash prompt

    Well I have had a google about, and have read man-bash > PS1 & man-bash > PROMPTING... but I still don't geddit!
    My preset bash prompt is this:
    Code:
    stephen@linux-ahy5:~>
    My response to
    Code:
    echo $PS1
    is:
    Code:
    $(ppwd \l)\u@\h:\w>
    My current root prompt is:
    Code:
    linux-ahy5:/home/stephen #

    If I set a new PS1 it (more or less!) works as expected.

    Working from the right, I think I understand that:

    Code:
    $(ppwd \l)\u@\h:\w>
    The > is just an echoed character after the:
    \w which shows the PWD, or if I am in /stephen/home, working as stephen it shows ~
    the colon is just another echoed character.
    The \h shows ?? I guess brief hostname,
    The \u shows me , the user, as stephen, and the @ is echoed:
    So; \u@\h:\w> shows:
    stephen@linux-ahy5:~> .... so far so good. But; if I add, change or delete any of these components, I get the error message:
    Code:
    syntax error near unexpected token `newline'
    so it must be somewhere in the part:
    Code:
    $(ppwd \l)
    .... which is where I get confused. A stab in the dark: Does the $ mean:
    "If the UID is 000 then do what is in brackets if not do the rest"?
    if this is so, does the "(ppwd \l)" mean "prompt for password", and why does not the $ take a forward slash before? What does the "\l" part do in this context?

    I am not especially unhappy with the current one, but as manipulating the prompt is often offered as "Lesson 1" in any intro to linux CLI, it is frutrating not to be able to do this!
    One thing is that I can see no reason to be told by the prompt that I am working in Linux, I cannot see myself swapping in to PERL or PYTHON any time soon, also I have no real idea what the "linux-ahy5" part of the prompt means!


    For convenience here is the "Prompting" section of man bash:
    PROMPTING

    When executing interactively, bash displays the primary
    a command. Bash allows these prompt strings to be cus
    tomized by inserting a number of backslash-escaped special
    characters that are decoded as follows:
    \t the current time in HH:MM:SS format
    \d the date in "Weekday Month Date" format
    (e.g., "Tue May 26")
    \n newline
    \s the name of the shell, the basename of $0
    (the portion following the final slash)
    \w the current working directory
    \W the basename of the current working direc
    tory
    \u the username of the current user
    \h the hostname
    \# the command number of this command
    \! the history number of this command
    \$ if the effective UID is 0, a #, otherwise a
    $
    \nnn the character corresponding to the octal
    number nnn
    \\ a backslash
    \[ begin a sequence of non-printing characters,
    which could be used to embed a terminal con
    trol sequence into the prompt
    \] end a sequence of non-printing characters

    The command number and the history number are usually dif
    ferent: the history number of a command is its position in
    the history list, which may include commands restored from
    the history file (see HISTORY below), while the command
    number is the position in the sequence of commands exe
    cuted during the current shell session. After the string
    is decoded, it is expanded via parameter expansion, com
    mand substitution, arithmetic expansion, and word split
    ting.

    Last edited by WakouonSuSe; 02-19-2009 at 10:46 AM. Reason: addenda

  2. #2
    Just Joined!
    Join Date
    Oct 2004
    Posts
    62
    Here are my prompts , in color (from .bashrc)

    for my home....

    # background cyan (46) - char (fg) bold white (37:1)
    PS1="\[\033[37;1;46m\]`date "+%a %d"` \w\033[0m\] "

    when I am "superuser" (insert in /root./.bashrc - use "superuser")...

    # root --> bg red (41) - char (fg) bold white (37:1)
    PS1="\[\033[37;1;41m\]`date "+%a %d"` \w\033[0m\] "
    Bye.

  3. #3
    Just Joined!
    Join Date
    Feb 2009
    Posts
    12
    Thank-you, but that is no help at all!

    I need to know why any manipulation of my current "$(ppwd \l)\u@\h:\w>" returns
    bash: syntax error near unexpected token `newline'

    even if I "PS1= EXACTLY THE SAME AS echo $PS1"
    and what the $(ppwd \l) means....

  4. #4
    Just Joined!
    Join Date
    Oct 2004
    Posts
    62
    Sorry....I didn't read well...
    And now.... an "uncorrect" advice... RTFM !

  5. #5
    Just Joined!
    Join Date
    Feb 2009
    Posts
    12
    and the first line of my original post.....?
    have read man-bash > PS1 & man-bash > PROMPTING... but I still don't geddit!

  6. #6
    Just Joined!
    Join Date
    Nov 2007
    Posts
    46
    bumpety bump

  7. #7
    Just Joined!
    Join Date
    Oct 2004
    Posts
    62
    Don't take "RTFM" too literally... I was only upset by the two emoticons!
    However I don't know the answer to your problem... and I don't care nor
    I have time to lose... I only wanted you to know prompts alternative from the
    standard. But if you are OK with your prompts.... no problem.

  8. #8
    Just Joined!
    Join Date
    Nov 2007
    Posts
    46
    Sorry about the 'moticons, they were supposed to convey my confusion, not a comment about you...

  9. #9
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    The key will reside in whatever "ppwd" is.

    There's a pwd command (with a single 'p') that is used to show the current path. I assume that your "ppwd" is a custom command, script or function, but since I have no idea what it is of what does it do, I can't give any more concrete info.

    The syntax $(whatever) will expand to the output of whatever command there's inside. In other words, "ppwd \l" (whatever that means) is run, and it's output is dumped in the place where "$(ppwd \l)" was before.

  10. #10
    Linux Guru Jonathan183's Avatar
    Join Date
    Oct 2007
    Posts
    2,941
    I found this useful ... having said that I tend to go with the default prompt unless I am chroot'in.

Page 1 of 2 1 2 LastLast

Posting Permissions

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