I created a new user. When I su into the new user, I get the following bash prompt:

\[\e]0;\u@\h: \w\a\]\u@\h:\w$

For what it's worth, I created this user with the following Ansible task:

  name: "{{ project_name }}"
  create_home: yes

Edit: grep PS1 ~/.bashrc gives

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
  • 3
    What does grep PS1 ~/.bashrc show (when being the new user)? – PerlDuck Sep 1 '18 at 15:29
  • That ^^^. The \u is user \w is current directory, \h is hostname. You have a prompt that is not set correctly. – Rinzwind Sep 1 '18 at 15:37
  • 1
    ... or possibly you have set a bash-appropriate PS1 but are actually running a different login shell (such as dash) that doesn't know how to interpret the escapes – steeldriver Sep 1 '18 at 16:00
  • 1
    @PerlDuck I can get the reported behavior by sourcing the default ~/.bashrc from a dash shell - while it's not hard to believe that ansible might be configured to create users with /bin/sh as the login shell, it's more curious why it would source one of bash's rc files (if that is in fact what's happening). Unless maybe the OP is setting a bash-specific PS1 via ~/.profile? – steeldriver Sep 1 '18 at 16:34
  • 1
    I deleted the user, and then recreated it using adduser. Since the home directory already existed, adduser reported that it would skip the step of copying over the skeleton. When I su into the refreshed user, the bash prompt now works. Then, when I type dash, it goes back to the broken parsing. So the ansible dash theory does seem plausible. – Doug Bradshaw Sep 1 '18 at 16:40

This turned out to be a mixed shell problem. The prompt constant was set to something that the ansible default shell (dash?) couldn't parse. To solve it, I just specified bash as the default shell.

    name: "{{ project_name }}"
    create_home: yes
    shell: /bin/bash
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.