LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   # sign instead of $ when user terminal (https://www.linuxquestions.org/questions/slackware-14/sign-instead-of-%24-when-user-terminal-4175707843/)

zrdc28 02-11-2022 05:13 AM

# sign instead of $ when user terminal
 
I just did a clean install of Slackware 15, everything went well except I have 2 problems. when in user mode terminal displays a # sign.
I have searched and tried everything I found on web but to no joy.


My second problem is that I cannot get .bashrc to run when in root
to be able to add colors, aliases etc. I assume that one problem solved will probably correct both. but I have not been able to find that solution.

https://www.linuxquestions.org/quest...eply&p=6163004

I found the answer in my own posts from about 18 months ago. getting old is
not always fun!

marav 02-11-2022 05:31 AM

You can find a lot of .bashrc examples here:

http://dotshare.it/category/shells/bash/

GazL 02-11-2022 05:38 AM

Here's what I use:

Code:

# ~/.bash_profile ######################################################

case $- in
*i* )  # Interactive shell
      if [ -f ~/.bashrc ]; then
          . ~/.bashrc
      fi
      ;;
esac

########################################################################

Code:

# ~/.bashrc ############################################################

[ -r "$ENV" ]  &&  . "$ENV"
[ -r /etc/bashrc ]  &&  . /etc/bashrc


shopt -s checkwinsize          # Keep track of terminal size

# Aliases:

alias less='less -XFRM'

# Bail out if we're not on a full-feature terminal:
if [ "$TERM" == 'dumb' ]; then
  return 0
fi

# ANSI Terminal control sequences to implement text styles,
# for use in prompts (and/or elsewhere):
declare -A style=(
  [default]=$( tput -S <<< $'sgr0\nop' )
  [prompt]=$( tput -S <<< $'sgr0\nop\nbold' )
  [input]=$( tput -S <<< $'sgr0\nop\nbold\nsetaf 5' )
  [warning]=$( tput -S <<< $'sgr0\nop\nbold\nsetaf 3' )
  [error]=$( tput -S <<< $'sgr0\nop\nbold\nsetaf 1' )
)

# Bash prompts:
#  'trap' ensures we clean up after ourselves on exit.
trap "tput -S <<< $'sgr0\nop'" EXIT
PS1=\\[${style[prompt]}\\]\\$\ \\[${style[input]}\\]
PS2=\\[${style[prompt]}\\]\>\ \\[${style[input]}\\]
PS0=${style[default]}

########################################################################


shelldweller 02-11-2022 07:55 AM

Quote:

Originally Posted by zrdc28 (Post 6328230)
I just did a clean install of Slackware 15, everything went well except I have 2 problems. when in user mode terminal displays a # sign.
I have searched and tried everything I found on web but to no joy.

That sounds like you are logging in as root user. Is it safe to assume you have created a non-root user and are logging in with that user? The # symbol indicates a root terminal, usually. Forgive me if this is too obvious and you have already ruled that out.

GazL 02-11-2022 08:01 AM

PS1=$ will display a '$'
PS1=\$ will also display a '$'
PS1=\\$ will display a '$' for non-root and a '#' for root.

And if that \\$ is followed by a word that could be interpreted as a shell variable, you need to do: PS1=\\\$word

Also, whether or not you use single or double quotes or not can confuse matters.

When setting PS1, you need to get the shell-escaping right in order to get the desired result.

pan64 02-11-2022 08:16 AM

you can find good pages on the net regarding PS1, like this: https://bashrcgenerator.com/

pm_a_cup_of_tea 02-11-2022 08:48 AM

For what its worth here is my .bashrc:

Code:

FILES=~/.config/bash/*

for f in $FILES; do
    source $f
done

Code:

$ls ~/.config/bash/

aliases  bashPrompt  colouredMan  dirColors  functions

Code:

$cat bashPrompt

#!/bin/bash

# Test to see what terminal we have and change the prompt accordingly
if [ $TERM == linux ]; then
        if [[ $(id -u) == 0 ]]; then
                export PS1="[\[\e[31m\]\u\[\e[m\]]-[\[\e[32m\]\w\[\e[m\]] \n\[$(tput sgr0)\][\[\e[36m\]\A\[\e[m\]]--> "
        else
                export PS1="[\[\e[1;34m\]\u\[\e[m\]]-[\[\e[32m\]\w\[\e[m\]] \n\[$(tput sgr0)\][\[\e[36m\]\A\[\e[m\]]--> "
        fi
else
        compile_prompt () {
          local EXIT=$?
          local CONNECTBAR_DOWN=$'\u250C\u2500\u257C'
          local CONNECTBAR_UP=$'\u2514\u2500\u257C'
          local SPLITBAR=$'\u257E\u2500\u257C'
          local ARROW=$'\u25B6'
          local c_gray='\e[01;30m'
          local c_blue='\e[0;34m'
          local c_cyan='\e[0;36m'
          local c_reset='\e[0m'
          # If root change color of prompt
          if [[ $(id -u) == 0 ]]
          then
                  local c_blue='\e[0;31m'
                  local c_gray='\e[00;30m'
          fi
       
          # > Connectbar Down
          # Format:
          #  (newline)(bright colors)(connectbar down)
          PS1="\n${c_gray}"
          PS1+="$CONNECTBAR_DOWN"
       
          # > Username
          # Format:
          #  (bracket open)(username)(bracket close)(splitbar)
          PS1+="[${c_blue}\u${c_gray}]"
          PS1+="$SPLITBAR"
       
          # > Jobs
          # Format:
          #  (bracket open)(jobs)(bracket close)(splitbar)
          PS1+="[${c_blue}\j${c_gray}]"
       
          # > Exit Status
          # Format:
          #  (bracket open)(last exit status)(bracket close)(splitbar)
          PS1+="[${c_blue}${EXIT}${c_gray}]"
          PS1+="$SPLITBAR"
       
          # > Time
          # Format:
          #  (bracket open)(time)(bracket close)(newline)(connectbar up)
          PS1+="[${c_blue}\D{%H:%M:%S}${c_gray}]\n"
          PS1+="$CONNECTBAR_UP"
       
          # > Working Directory
          # Format:
          #  (bracket open)(working directory)(bracket close)(newline)
          PS1+="[${c_blue}\w${c_gray}]\n"
       
          # > Arrow
          # NOTE: Color must be escaped with '\[\]' to fix the text overflow bug!
          # Format:
          #  (arrow)(color reset)
          PS1+="$ARROW \[\e[0m\]"
        }
       
        PROMPT_COMMAND='compile_prompt'
fi

The xterm prompt was lifted from the nord color theme, with some changes.

The chances are you do not want to do it the way that I have

TheRealGrogan 02-11-2022 01:14 PM

You didn't, on the off chance, make your user UID 0 did you? (i.e. that is allowed so you can have multiple root accounts by doing that)

That would cause your prompt to show #


All times are GMT -5. The time now is 03:13 AM.