LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 05-09-2017, 01:07 PM   #1
Dauer
Member
 
Registered: Sep 2004
Location: Denmark
Distribution: Slackware 14.2
Posts: 40

Rep: Reputation: 20
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;
 
Old 05-09-2017, 01:09 PM   #2
55020
Senior Member
 
Registered: Sep 2009
Location: Yorks. W.R. 167397
Distribution: Slackware
Posts: 1,307
Blog Entries: 4

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

You want \$ not \#
 
1 members found this post helpful.
Old 05-09-2017, 01:20 PM   #3
Dauer
Member
 
Registered: Sep 2004
Location: Denmark
Distribution: Slackware 14.2
Posts: 40

Original Poster
Rep: Reputation: 20
But if I write \$ I get the $ sign as root. I want the # sign as root.
 
Old 05-09-2017, 01:29 PM   #4
55020
Senior Member
 
Registered: Sep 2009
Location: Yorks. W.R. 167397
Distribution: Slackware
Posts: 1,307
Blog Entries: 4

Rep: Reputation: Disabled
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+="\\\$ "

Last edited by 55020; 05-09-2017 at 01:31 PM.
 
2 members found this post helpful.
Old 05-09-2017, 01:32 PM   #5
coralfang
Member
 
Registered: Nov 2010
Location: Bristol, UK
Distribution: Slackware, FreeBSD
Posts: 748
Blog Entries: 3

Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by Dauer View Post
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='\$ '
 
1 members found this post helpful.
Old 05-09-2017, 01:36 PM   #6
phenixia2003
Member
 
Registered: May 2006
Location: France
Distribution: Slackware
Posts: 876

Rep: Reputation: 760Reputation: 760Reputation: 760Reputation: 760Reputation: 760Reputation: 760Reputation: 760
Hello,

Quote:
Originally Posted by Dauer View Post
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
 
1 members found this post helpful.
Old 05-09-2017, 01:54 PM   #7
Dauer
Member
 
Registered: Sep 2004
Location: Denmark
Distribution: Slackware 14.2
Posts: 40

Original Poster
Rep: Reputation: 20
Okay, now I works. I was not aware that there was a difference between single and double quotes.
 
Old 05-09-2017, 02:33 PM   #8
onebuck
Moderator
 
Registered: Jan 2005
Location: Summer Midwest USA, Central Illinois, Winter Central Florida
Distribution: SlackwareŽ
Posts: 13,374
Blog Entries: 31

Rep: Reputation: 2562Reputation: 2562Reputation: 2562Reputation: 2562Reputation: 2562Reputation: 2562Reputation: 2562Reputation: 2562Reputation: 2562Reputation: 2562Reputation: 2562
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!
 
Old 05-09-2017, 02:44 PM   #9
montagdude
Senior Member
 
Registered: Apr 2016
Distribution: Slackware
Posts: 1,491

Rep: Reputation: 1110Reputation: 1110Reputation: 1110Reputation: 1110Reputation: 1110Reputation: 1110Reputation: 1110Reputation: 1110Reputation: 1110
Quote:
Originally Posted by Dauer View Post
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.)
 
Old 05-09-2017, 02:52 PM   #10
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-14.2.1.2 on Lenovo Thinkpad W520
Posts: 8,854

Rep: Reputation: Disabled
Quote:
Originally Posted by Dauer View Post
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.
 
  


Reply

Tags
bash, root


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] /etc/bashrc ,dircolors and /root/.bash_profile ,/.bashrc not exist in LFS-7.5(sec9.3) jaassi Linux From Scratch 2 09-20-2014 05:04 PM
[SOLVED] How to use my /home/kangjoo/.bashrc rather than root/.bashrc kangjoo.lee Linux - Newbie 2 11-05-2012 03:38 PM
bashrc and root fluxism Linux - Newbie 9 06-16-2009 09:11 AM
Can't Modify .bashrc as root Ukuntu Linux - General 2 04-07-2009 09:58 AM
need root .bashrc .bash_profile darkRoom Slackware 5 04-30-2005 03:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 01:59 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration