Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are these shell escape characters?

I'm trying out the coffee script repl inside Emacs (under ArchLinux) and I'm seeing these escape characters surrounding the prompt:

[1Gcoffee> [0K[9G

These shouldn't be colors as I already enabled the ansi-color-for-comint-mode. So does anyone recognize these?

P.S.: Funny thing is I don't have this issue under my Emacs+Cygwin setup!

like image 522
Nicolas Buduroi Avatar asked Jul 07 '11 02:07

Nicolas Buduroi


People also ask

What is escape character in shell?

Escaping is a method of quoting single characters. The escape (\) preceding a character tells the shell to interpret that character literally. With certain commands and utilities, such as echo and sed, escaping a character may have the opposite effect - it can toggle on a special meaning for that character.

How do you escape special characters in shell?

Escape characters. Escape characters are used to remove the special meaning from a single character. A non-quoted backslash, \, is used as an escape character in Bash. It preserves the literal value of the next character that follows, with the exception of newline.

Which characters should be escaped in Bash?

These are all special characters, which may have to be escaped to preserve their literal meaning within double quotes: $ <dollar-sign>, e.g. $() and ${} ` <grave-accent>, also known as the backquote operator. ” <quotation-mark>, when we need a double quote within double quotes.

What is escape character in shell script?

The escape () preceding a character tells the shell to interpret that character literally. With certain commands and utilities, such as echo and sed, escaping a character may have the opposite effect – it can toggle on a special meaning for that character. How do I remove special characters from a UNIX shell script?

What characters should be escaped in Bash?

Characters that need escaping are different in Bourne or POSIX shell than Bash. Generally (very) Bash is a superset of those shells, so anything you escape in shellshould be escaped in Bash. A nice general rule would be "if in doubt, escape it".

What happens when you escape a special character in a command?

With certain commands and utilities, such as echo and sed, escaping a character may have the opposite effect – it can toggle on a special meaning for that character. How do I remove special characters from a UNIX shell script?

How can I escape characters in Linux shell command 4 cut?

List of characters which needs to be escaped in a linux shell command 4 cut : use "/" as a delimiter See more linked questions Related 7 How can I escape characters in SQLite via bash shell?


1 Answers

I don't know where they're coming from (something to do with your shell prompt, obviously, but it's hard to say more than that).

I read them as:

  • ESC[1G - Move to column 1 (Cursor Character Absolute)
  • ESC[0K - Erase to right
  • ESC[9G - Move to column 9

It looks like an attempt by the shell to ensure that the prompt is at the far left of an empty line. Not sure what shell you have, but zsh does something similar when the PROMPT_SP option is enabled. I don't think it uses the above sequences, though.

Many, many, control sequences can be found here. Note that the sequence "ESC[" is interpreted as a "Control Sequence Introducer" (CSI) and is shown as that on that page.

like image 173
brontitall Avatar answered Sep 20 '22 15:09

brontitall