Search code examples
bashps1

Changing vowels to numbers in Bash prompt PS1


I am trying to change my user prompt bash so that instead of showing up the vowels, it shows the number corresponding to that vowel. So, a -> 1, e -> 2, i -> 3, o -> 4, u -> 5.

So far what I achieved is all the vowels with the same number as you can see below. However I don't know how to do the aforementioned.

PS1='${USER//[io]/4}@ \D{%d-%m-%Y} - \w$ '
  • Current name output: L4l4p4p (Lolipop)

  • Expected name output: L4l5p4p

Can anyone help?

Thank you


Solution

  • With bash and parameter expansion:

    PS1='$(USER="${USER//a/1}"; USER="${USER//e/2}"; USER="${USER//i/3}"; USER="${USER//o/4}"; echo "${USER//u/5}")@ \D{%d-%m-%Y} - \w$ '