SCIENTIFIC-LINUX-USERS Archives

November 2017

SCIENTIFIC-LINUX-USERS@LISTSERV.FNAL.GOV

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Reply To:
Date:
Sat, 11 Nov 2017 10:05:09 -0800
Content-Type:
text/plain
Parts/Attachments:
text/plain (27 lines)
On 2017-11-11 03:28, Tom H wrote:
> On Fri, Nov 10, 2017 at 10:15 PM, Steven Haigh <[log in to unmask]> wrote:
>>
>> For what its worth, I've been using this for years:
>> PS1="\[\033[01;37m\]\$? \$(if [[ \$? == 0 ]]; then echo \"\[\033[01;32m\]
>> \342\234\223\"; else echo \"\[\033[01;31m\]\342\234\227\"; fi) $(if [[ ${EUID}
>> == 0 ]]; then echo '\[\033[01;31m\]\h'; else echo '\[\033[01;32m\]\u@\h'; fi)\
>> [\033[01;34m\] \w \$\[\033[00m\] "
> 
> If you use single-quotes for PS1, you can use unescaped double-quotes
> and dollar signs within it. It makes it more legible:
> 
> PS1='\[\033[01;37m\]$? $(if [[ $? == 0 ]]; then echo
> "\[\033[01;32m\]\342\234\223"; else echo
> "\[\033[01;31m\]\342\234\227"; fi) $(if [[ ${EUID} == 0 ]]; then echo
> "\[\033[01;31m\]\h"; else echo "\[\033[01;32m\]\u@\h";
> fi)\[\033[01;34m\] \w \$\[\033[00m\] '
> 
> You might be better off using "printf" (it's a bash builtin) because
> "echo" might not interpret escapes depending on the bash or shell
> options that are set.

It works for him, apparently. So that's good. Now, in pedantic mode each of the 
\033 strings can be changed to \e for easier readability.

{^_-}

ATOM RSS1 RSS2