0

According to the GNU Bash manual (section 3.1.2.4 ANSI-C Quoting) $'\E' should expand to "an escape character (not ANSI C)". What is this escape character? Is it the character equivalent to backslash '\' itself whose function is to preserves the literal value of the next character that follows?

How can it be demonstrated on the terminal, say using the command echo?

1

1 Answer 1

3

$'\E' represents the ASCII escape character (eg. \x1b/\033/CtrlV + Esc), rather than a backslash:

% printf '%x\n' \'$'\E'
1b

One common use of this character is to indicate a control sequence: an alternate interpretation of a portion of subsequent bytes. For example, it's commonly used in shell prompts as part of an ANSI escape sequence to indicate that the terminal should colour some text, or by applications to ask the terminal to position the cursor, and much more.*

% printf '\033[36m%s\033[0m\n' 'this is in cyan'
this is in cyan
% printf '\033[2J'  # clear the screen

* For most of these use cases, you usually want to use tput instead, though, which is terminfo aware and somewhat more intuitive to use. These two basic examples should be pretty much universally understood, though.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .