Changing vowels to numbers in Bash prompt PS1

184 views Asked by At

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

2

There are 2 answers

0
Cyrus On BEST ANSWER

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$ '
1
KamilCuk On

I would use sed.

PS1='$(<<<"$USER" sed "s/a/1/g;s/e/2/g;s/i/3/g;s/o/4/g;s/u/5/g") '