• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Programming environment?

Resolved: Programming environment?

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I’m trying to add color to a part of my Ubuntu bash prompt. This part isn’t working: (\e[0;31m\1\e[m) It works, however, if I place it within the PS1 export.
What am I doing wrong?

Answer:

Let’s imagine you asked this question:
  • Why does putting \e\[0;31m in PS1 variable content result in a colored text output, when putting the same string inside sed s command replacement expression does not result in colored output?

It’s because Bash when printing the content of PS1 variable changes the sequence of two characters \ and e by the byte with the value 033 octal or 0x1b hexadecimal. In contrast, for sed the sequence of \ e characters as part of replacement expression is technically invalid and in practice is not interpreted specially and with GNU sed just results in a literal e character on output.
If you want to output the hex byte 0x1b with GNU sed you can use the \x1b escape sequence, or you can rely on Bash ANSI-C quoting to pass the byte literally to sed.

If you have better answer, please add a comment about this, thank you!

linux
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Why is NGINX’s $request_uri empty?

24/03/2023

Resolved: How to convert Java bytecode to Webassembly using CheerpJ compiler

24/03/2023

Resolved: Is pandas groupby() function always produce a DataFrame with the same order respect to the column we group by?

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.