LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-30-2015, 01:02 AM   #16
andrew.comly
Member
 
Registered: Dec 2012
Distribution: Trisquel-Mini 7.0, Lubuntu 14.04, Debian lxde 8.0
Posts: 311

Original Poster
Blog Entries: 2

Rep: Reputation: 16
Talking add export


Quote:
Originally Posted by goumba View Post
Now, if I add export, the prompt works:
Code:
if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
    export PS3=$'\e[01;33mSelection: \e[0m'
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    export PS3='Selection: '
fi
This works now, but after I added "export=" and saved, I then opened a new terminal and entered
Code:
openbox --reconfigure
This probably wouldn't matter. However I still wonder if this will still work in a few hours? And another thing, what is the meaning of:
Code:
{debian_chroot:+($debian_chroot)}
??

I guess I will wait 3 days this time to "Mark as solved". Haste makes waste.
 
Old 07-30-2015, 01:14 AM   #17
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Fedora, OpenSUSE, FreeBSD, OpenBSD, macOS (hack). Past: Debian, Arch, RedHat (pre-RHEL).
Posts: 1,335
Blog Entries: 7

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
I myself am curious as to why PS3 must be exported while PS1 not. I'm guessing it has to do with the nature of 'interactive' shells, but I'm no expert myself. Or perhaps, as it is expected to be used in the script with the select built-in, it does not normally get inherited by child processes.

Last edited by goumba; 07-30-2015 at 01:21 AM.
 
1 members found this post helpful.
Old 07-30-2015, 03:15 AM   #18
andrew.comly
Member
 
Registered: Dec 2012
Distribution: Trisquel-Mini 7.0, Lubuntu 14.04, Debian lxde 8.0
Posts: 311

Original Poster
Blog Entries: 2

Rep: Reputation: 16
"'\e" method for PS1: caret stuck in prompt

The shortform "'\e" method doesn't work for PS1:
Code:
PS1='${debian_chroot:+($debian_chroot)}\e[01;31m\u\e[01;33m@\e[01;34m\h\e[01;33m:\e[01;35m\w\e[01;32m\$ \e[00m'
When I replace the longform (that fixed my prompt , reply #16, 2 replies above) with the above line of shortform, this causes the caret to be stuck in the prompt. E.g. the cursor instead of being after the prompt is at the very 1st letter. You type and it ends up 'inserting(deleting)' out the prompt. Of course any shortform never works in as many situations nor is as robust as the longform.

Maybe did I type something wrong? Probably if I continue to read the bash textbook I'll find that the shortform above ('\e method) has some combination of two characters that I should have used a backslash along with a strong/weak quote to avoid expanding.

Happy bash reading!!

Last edited by andrew.comly; 07-30-2015 at 03:19 AM.
 
Old 07-30-2015, 03:29 AM   #19
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Fedora, OpenSUSE, FreeBSD, OpenBSD, macOS (hack). Past: Debian, Arch, RedHat (pre-RHEL).
Posts: 1,335
Blog Entries: 7

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
Quote:
Originally Posted by andrew.comly View Post
The shortform "'\e" method doesn't work for PS1:
Code:
PS1='${debian_chroot:+($debian_chroot)}\e[01;31m\u\e[01;33m@\e[01;34m\h\e[01;33m:\e[01;35m\w\e[01;32m\$ \e[00m'
When I replace the longform (that fixed my prompt , reply #16, 2 replies above) with the above line of shortform, this causes the caret to be stuck in the prompt. E.g. the cursor instead of being after the prompt is at the very 1st letter. You type and it ends up 'inserting(deleting)' out the prompt. Of course any shortform never works in as many situations nor is as robust as the longform.

Maybe did I type something wrong? Probably if I continue to read the bash textbook I'll find that the shortform above ('\e method) has some combination of two characters that I should have used a backslash along with a strong/weak quote to avoid expanding.
No, you did not do anything wrong, technically.

I remember there being a quirk about PS1 and escape codes, and bash's handling of the length of a line. Argh, I can't remember exactly what it was right now, nor find the resource in which I read it. When I find it, I'll give the details here.
 
1 members found this post helpful.
Old 07-30-2015, 03:31 AM   #20
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Fedora, OpenSUSE, FreeBSD, OpenBSD, macOS (hack). Past: Debian, Arch, RedHat (pre-RHEL).
Posts: 1,335
Blog Entries: 7

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
Found it:

http://mywiki.wooledge.org/BashFAQ/053

As you'll notice, PS1 as included in debian's default .bashrc escapes the color codes with \[ and \].

All together that FAQ is a good thing to get to know.

FWIW I use the termcap method (tput setaf etc...) as it supposedly has better compatibility than using the ANSI escape codes directly.

Last edited by goumba; 07-30-2015 at 03:37 AM.
 
1 members found this post helpful.
  


Reply

Tags
bash, prompt


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Make Bash prompt look like Windows C:\ prompt -- *PROBLEM* arkadios Linux - General 5 07-24-2012 11:29 AM
[SOLVED] Bash prompt. It looks fine initially, but there seems to be a hidden error. WyattOil Linux - General 2 06-01-2011 06:55 PM
Newbie with YDL on PS3 coming for help with Kboot prompt jekylnhyde Linux - Newbie 3 03-07-2010 07:37 AM
failed PS3 linux install, can i rescue my PS3 kells Linux - Hardware 3 01-05-2010 11:33 AM
Cannot get past install at kboot prompt - YDL 6.0 on PS3 valentino46 Linux - Newbie 7 08-22-2008 06:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration