2

Currently my prompt is:

xiaobai@dnxb:/tmp$
root@dnxb:/tmp# 

My desired prompt:

xb@dnxb:/tmp$
rt@dnxb:/tmp# 

My idea is alias of username, so i tried reuse the same uid to create a new user:

xiaobai@dnxb:~$ sudo useradd -ou 1000 -g1000 -d /home/xiaobai -s /bin/bash xb
xiaobai@dnxb:~$ su
Password: 
root@dnxb:/home/xiaobai# passwd xb
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
root@dnxb:/home/xiaobai# exit
xiaobai@dnxb:~$ su xb
Password: 
xiaobai@dnxb:~$ pwd
/home/xiaobai
xiaobai@dnxb:~$ PS1='\u:\W\$ '
xiaobai:~$ exit
xiaobai@dnxb:~$ id
uid=1000(xiaobai) gid=1000(xiaobai) groups=1000(xiaobai),27(sudo)
xiaobai@dnxb:~$ 

It doesn't change to xb for PS1 '\u'. If so, how ?

3
  • 1
    The kernel know you as 1000. When bash checks the name of 1000, the first entry is your long name. Commented Oct 19, 2016 at 15:11
  • @GiacomoCatenazzi I have to use startx to start gdm after i do this. It just hang when boot up.
    – 林果皞
    Commented Oct 19, 2016 at 15:33
  • No problem anymore after i remove this user from /etc/passwd and /etc/shadow.
    – 林果皞
    Commented Oct 19, 2016 at 15:39

2 Answers 2

8

What's wrong with setting manually?

PS1="xb@\h:\w\$ "
3
  • Thanks, my /home/xiaobai/.bash_aliases is symlink to /root/.bash_aliases, so it disrupt my thinking to put PS1 in the same file. But actually i can put PS1 in ~/.bashrc or do a simple uid checking to set PS1.
    – 林果皞
    Commented Oct 19, 2016 at 15:24
  • 2
    This is not alias, it's better to use ~/.bashrc. Commented Oct 19, 2016 at 15:27
  • Agree, setting PS1 should be handled in ~/.bashrc.
    – Jeter-work
    Commented Oct 19, 2016 at 15:59
5

If you want to use the same PS1 for both/all users, you can use parameter expansion to remove the vowels from the username:

PS1='${USER//[aeiou]}@\h:\w\$ '
2
  • Amazing, is this in the manual ? I can't found it in man bash.
    – 林果皞
    Commented Oct 19, 2016 at 16:24
  • 2
    It's here, under ${parameter/pattern/string}: gnu.org/software/bash/manual/html_node/… (my man page calls it pattern substitution, but that web page doesn't seen have any descriptive names for the different expansions)
    – ilkkachu
    Commented Oct 19, 2016 at 16:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .