LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   main non-root user shell prompt lost (https://www.linuxquestions.org/questions/slackware-14/main-non-root-user-shell-prompt-lost-4175470391/)

textillis 07-21-2013 09:57 AM

main non-root user shell prompt lost
 
Sooo embarrassed...

While fooling around (let's call it "exploring the cli") with two
files:
  1. .bashrc_profile and
  2. .bashrc,
I have managed to completely "disappear"
my main user's shell prompt!

At the console prompt (or an xterm for that matter) I can log in as root; but when I try with my non-root user, on entering log and p/word, the prompt goes to null, then, after 3 or 4 seconds, the main prompt is restored.

I know that I have to reset it by using something like:
<PS1=\u\h\w$>
but I do not know where to begin to do this.

And all the help notes I googled assume that one is starting with the bare minimum:
<bash-4.2$ >
or something like that, the very thing which has vanished.
All I have is a sober, forbidding-looking:
<bash-4.2#>

Anyone? I feel all orphaned, marooned, widowed, bereft even of the right metaphor ....

Didier Spaier 07-21-2013 10:02 AM

(wrong answer)

NonNonBa 07-21-2013 10:43 AM

Hi,

Login in root, then move the .bash* of your user:

Code:

mv /home/<user>/.bashrc,{.old}
mv /home/<user>/.bash_profile{,.old}

If it still does not work, check in /etc/passwd the shell you have defined for this user:

Code:

grep ^user: /etc/passwd
The last field of the line is the defined shell.

tronayne 07-21-2013 10:44 AM

Go look in /etc/profile, there's a section:
Code:

# Set a default shell prompt:
#PS1='`hostname`:`pwd`# '
if [ "$SHELL" = "/bin/pdksh" ]; then
 PS1='! $ '
elif [ "$SHELL" = "/bin/ksh" ]; then
 PS1='! ${PWD/#$HOME/~}$ '
elif [ "$SHELL" = "/bin/zsh" ]; then
 PS1='%n@%m:%~%# '
elif [ "$SHELL" = "/bin/ash" ]; then
 PS1='$ '
else
 PS1='\u@\h:\w\$ '
fi
PS2='> '
export PATH DISPLAY LESS TERM PS1 PS2

Copy the one you like to your ~/.profile, ~/.bashrc or ~/.bashrc_profile. file (hint: I think the default BASH prompt is PS1='\u@\h:\w\$).

You can also edit the preferences for your terminal emulator program and turn on the "make it a login shell" option.

Or, if you did something in one of the .bash* files with PS1, remove that and you'll get the system default.

Hope this helps some.

textillis 07-21-2013 10:57 AM

Non non ba, tronayne, thanks kindly for detailed responses.
in the meantime, I actually worked out one possible way how to fix it:
I simply logged in as root and removed that user's .bashrc and .bashrc_profile, which gave me the default back.

Now, I'll go to work on your suggestion tronayne, of selecting one i like
(the one I had worked up before was simply the one you reference: <PS1='\u@\h:\w\$>

(feels kinda good having worked something out for myself for the first time :) )

textillis 07-21-2013 11:20 AM

Quote:

Originally Posted by NonNonBa (Post 4994203)
Hi,

Login in root, then move the .bash* of your user:

Code:

mv /home/<user>/.bashrc,{.old}
mv /home/<user>/.bash_profile{,.old}

If it still does not work, check in /etc/passwd the shell you have defined for this user:

Code:

grep ^user: /etc/passwd
The last field of the line is the defined shell.

The answer to that query was /home/user:/bin/bash, which is interesting, but doesn't tell me how to get my old customized prompt back.

Thanks again

tronayne 07-21-2013 11:51 AM

Well, the one I use (with KornShell, I don't use BASH) is
Code:

PS1='${HOST}-${USER}-${PWD}: '
)
(it looks like this: fubar-trona-/home/trona: )

The only variable that isn't "just there" is ${HOST} which I define with
Code:

export HOST="`uname -n`"
For what it's worth...

onebuck 07-21-2013 02:04 PM

Member Response
 
Hi,

I like to provide my users with this;
Code:

sample .bash_profile; 
~$ cat .bash_profile
#-----------------cut----------------- 
# .bash_profile
#08-30-06 12:21

# Source .bashrc
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

#-----------------cut end--------------

Code:

cat .bashrc
#-----------------cut-------------------

#.bashrc
#08-30-06 12:20

# 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                                                                         
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
#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 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

#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


#-----------------cut end--------------

I let them modify to suit their needs.
Hope this helps!

textillis 07-22-2013 12:47 AM

Quote:

Originally Posted by tronayne (Post 4994233)
Well, the one I use (with KornShell, I don't use BASH) is
Code:

PS1='${HOST}-${USER}-${PWD}: '
)
(it looks like this: fubar-trona-/home/trona: )

The only variable that isn't "just there" is ${HOST} which I define with
Code:

export HOST="`uname -n`"
For what it's worth...

Nice.
1. But what about simply "\h" to render "hostname"; which is what works for me?
2. I notice you use single ` ... `; are these equivalent in scripting to " ... " (a key with which I am more comfortable: ie: i can actually hit it accurately, nearly every time :) )?
3. slack is sinking into my fibres, into my dreams and taking up waaaayyy too much of my waking moments for me to continue to claim the tag of normality. ;)

cheers

textillis 07-22-2013 12:57 AM

Quote:

Code:

mv /home/<user>/.bashrc,{.old}
mv /home/<user>/.bash_profile{,.old}


Hi, I was just wondering if you would mind clarifying a couple of things which occur to me about your response?
1. is {.old} equivalent to {~}? I notice that every time I create a file I get a back up automatically, ending in tilda (~) )
2. would you explain the grammar of:
Code:

grep ^user: /etc/passwd
for me, as I have never been able to wade through the man pages on grep sufficiently to grasp (or "grep") more than a bare outline of what it does, but your use of it above looks so helpful.

And thanks again,

textillis 07-22-2013 01:01 AM

Quote:

Originally Posted by onebuck (Post 4994283)
Hi,

I like to provide my users with this;
Code:

sample .bash_profile;

Thanks kindly Onebuck!

Would you go one further and tell me how i can save the aliases I have made in my ~/.bashrc so that they are available for root?

Once again, appreciate such a detailed, informative and pin-point-pertinent response!
Cheers,

NonNonBa 07-22-2013 03:43 AM

The a{x,y,z} expression is just a shortcut for writting ax ay az. So here it's a way to write mv /home/<user>/.bash_profile /home/<user>/.bash_profile.old (ooops, I realize there's a typo in the first line I gave, sorry). See man bash, "Brace expansion" section, for further details.

Per default, grep takes a regular expression. "^" means "beginning of the line", so here I just ask for printing the line(s) starting with the "user:" string. Regular expressions are a way to describe a line to match, by requesting things such a line, starting with A to H, followed by one or more digit(s), maybe followed by a string introduced with a column, and always ending with no or one or more spaces, equal, no or one or more spaces, then "Eric", "Kenny", "Kyle" or "Stan". Which gives something like ^[A-H][0-9]+(:[^ ]*)? *= *(Eric|Kenny|Kyle|Stan)$. You have a short introduction in man grep, but it's a rather complex topic... maybe man perlretut is a better introduction (Perl's IMHO the best and the funniest language to play with them).

Hope this feeds your curiosity. ;)

textillis 07-22-2013 03:55 AM

NonNonBa:
Thanks heaps for the detailed response.
Reading up big now.
(Your suggestion about perl has peeked my curiosity)

Didier Spaier 07-22-2013 04:10 AM

Before reading "man bash" I would recommend anyone reading the definition of the Shell Command Language in the POSIX standard, for following reasons:
  1. I am under the impression that its knowledge is "tacitly assumed" by writers of "man bash"
  2. It's (slightly) easier to read IMO
  3. It provides some examples
Only caveat, it's maybe not quite as good as remedy against insomnia ;)


Just my :twocents:

textillis 07-22-2013 05:46 AM

>Didier!
Thanks mon vieux.
I'll take up the challenge and see if I can keep awake through the introduction.

If so, I'll make it my "well-thumbed" guide.

Seriously apt suggestion, given my oft-publicly-declared aversion to man-pages,
and my oft-displayed need for the information in them to be transferred to my brain.


All times are GMT -5. The time now is 12:36 AM.