4

I wanted to print something like this on my gnome-terminal

[abc@host pwd]$ ************************************************************

using some manipulations in PS1 but the number of stars are dynamic depending on PS1 and terminal width. So can anyone plz suggest me the way to find out the length of PS1 i.e the actual string which will be displayed.

Kaunteya
  • 3,107
  • 1
  • 35
  • 66
  • 1
    `bash` doesn't provide access to the expanded value, but http://stackoverflow.com/questions/3451993/echo-expanded-ps1 has some pointers on how to modify the `bash` source code to do so. – chepner Feb 25 '13 at 15:53

1 Answers1

-3

It can't ve done portably IMO, as PS1 can contain escape sequences for color codes, (multiple) new lines too.

It can be calculated. But that's a really hard task. What if the user codes colorcodes in variable names (it's a common scenario), how to decide (during evaluation/counting the length) if that's something that the user wants to display or is only style information?

Zsolt Botykai
  • 50,406
  • 14
  • 85
  • 110