I would like to see the output of the escaped special characters used in setting up $PS1
. For example, placing \u
in PS1 will output the username of the current user.
So in essence:
omar @ ~ > echo -e '\u'
Expect:
omar
Actual output:
\u
I would like to see the output of the escaped special characters used in setting up $PS1
. For example, placing \u
in PS1 will output the username of the current user.
So in essence:
omar @ ~ > echo -e '\u'
Expect:
omar
Actual output:
\u
You can do it with parameter expansion with the @P
operator like this:
prompt="\u"; echo ${prompt@P}
As of Bash 4.4, you can use the @P
operator in Parameter expansion:
${parameter@operator}
The expansion is either a transformation of the value of parameter or information about parameter itself, depending on the value of operator. Each operator is a single letter:
@P
The expansion is a string that is the result of expanding the value of parameter as if it were a prompt
Here's some of the common special characters available to the PS1 command:
The following lists the special characters that can appear in the prompt variables PS0, PS1, PS2, and PS4
\a
A bell character
\d
The date, in "Weekday Month Date" format (e.g., "Tue May 26")
\e
An escape character
\H
The hostname
\u
The username of the current user
\w
The current working directory
Further Reading: