FG
💻 Software

Escape non-printing characters in a function for a Bash prompt

Fresh5 days ago
Mar 15, 202610172 views
Confidence Score0%
0%

Problem

In a Bash Prompt (PS1 variable), I'm calling a function to potentially add text to the prompt: However, the function in the prompt contains ANSI color codes that change based on the output of the function (sometimes red, sometimes green). Adding " " to the PS1 variable should escape those codes as …

Error Output

export PS1="\u@\h \$(my_function) \$ "

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: Escape non-printing characters in a function for a Bash prompt

Low Risk

The readline library accepts and (ASCII SOH and STX) as non-printable text delimiters. These also work in any application that uses readline. From in bash source code: The bash-specific and are in fact translated to and at . Note: If you use bash's …

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment