LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Root .bashrc (https://www.linuxquestions.org/questions/slackware-14/root-bashrc-4175605568/)

Dauer 05-09-2017 01:07 PM

Root .bashrc
 
Hi,
I have modified my user .bashrc and wanted to have my root bash look the same so I copied my user bashrc to /root. Works fine except for the hash sign. Instead of a # sign I get a 1.

This is driving me crazy. Why is this happening ?

Code:

PS1="\u";        # username
PS1+=" at ";       
PS1+="\h";        # host
PS1+=" in ";       
PS1+="\W";        # working directory
PS1+="\n";       
PS1+="\# ";

export PS1;


55020 05-09-2017 01:09 PM

https://tiswww.case.edu/php/chet/bas...ing-the-Prompt

You want \$ not \#

Dauer 05-09-2017 01:20 PM

But if I write \$ I get the $ sign as root. I want the # sign as root.

55020 05-09-2017 01:29 PM

So you're not doing the quotes and backslashes right. You need backslash-dollar in PS1. If you write PS1+="\$" then the backslash will disappear, because it's protecting the dollar.

Either of these will work:

PS1+='\$ '
PS1+="\\\$ "

coralfang 05-09-2017 01:32 PM

Quote:

Originally Posted by Dauer (Post 5708270)
But if I write \$ I get the $ sign as root. I want the # sign as root.

Make sure you use single quotes; for example:
Code:

PS1='\$ '

phenixia2003 05-09-2017 01:36 PM

Hello,

Quote:

Originally Posted by Dauer (Post 5708270)
But if I write \$ I get the $ sign as root. I want the # sign as root.

the backslash is not needed to get # sign :

Code:

$ PS1="\u at \h in \W\n# "
root at blackdog in ~
# echo $PS1
\u at \h in \W\n#

--
SeB

Dauer 05-09-2017 01:54 PM

Okay, now I works. I was not aware that there was a difference between single and double quotes.

onebuck 05-09-2017 02:33 PM

Member response
 
Hi,

I test for root or user to set the prompt. Notice the 'id' check via 'if' below;
Code:

#.bashrc
#08-30-06 12:20 gws copied loki:/root

# Add bin to path
export PATH="$PATH:$HOME/bin"

# Dynamic resizing
shopt -s checkwinsize
#
#save bash history so as to share

shopt -s histappend


PROMPT_COMMAND='history -a'

# Custom prompt
#PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

#08-29-06 11:40 gws

if [ `id -un` = root ]; then
  PS1='\[\033[1;31m\]\h:\w\$\[\033[0m\] '
 else
  PS1='\[\033[1;32m\]\h:\w\$\[\033[0m\] '
fi
#
# Add color
eval `dircolors -b`

#Terminus is a very nice Unicode font for the Linux console
#02-02-12 gws
#from dugan's site http://duganchen.ca/writings/slackware/fonts/

#04-30-12 11:41 removed
#
#if [ $TERM = "linux" ]; then
#    setfont ter-v16n
#fi

# User defined aliases
alias cls='clear'
alias clls='clear; ls'
alias ll='ls -l'
alias listlong='ls -l'
alias lsa='ls -A'
alias lsg='ls | grep'
alias lsp='ls -1 /var/log/packages/ > package-list'
alias na='nano'
alias web='links -g -download-dir ~/ www.google.com'

#08-29-06 11:50 gws

#To clean up and cover your tracks once you log off
#Depending on your version of BASH, you might have to use
# the other form of this command
  trap "rm -f ~$LOGNAME/.bash_history" 0

#The older KSH-style form
#  trap 0 rm -f ~$LOGNAME/.bash_history

Hope this helps.
Have fun & enjoy!
:hattip:

montagdude 05-09-2017 02:44 PM

Quote:

Originally Posted by Dauer (Post 5708288)
Okay, now I works. I was not aware that there was a difference between single and double quotes.

I know that vim at least will do syntax coloring to indicate whether what you are typing is a variable or plain text, and it correctly distinguishes between single- and double-quoted phrases. I'm sure other editors are smart enough to do that too. (Just a tip.)

Didier Spaier 05-09-2017 02:52 PM

Quote:

Originally Posted by Dauer (Post 5708288)
Okay, now I works. I was not aware that there was a difference between single and double quotes.

Cf. under 2.2.2 Single-Quotes and 2.2.3 Double-Quotes in the current POSIX specification of the Shell Command Language for the details.


All times are GMT -5. The time now is 06:39 PM.