What type of sequences are escape sequences starting with “33]”












12














I found many escape sequences in Bash starting with 33], but what are these sequences and why are they starting with 33]?










share|improve this question





























    12














    I found many escape sequences in Bash starting with 33], but what are these sequences and why are they starting with 33]?










    share|improve this question



























      12












      12








      12


      4





      I found many escape sequences in Bash starting with 33], but what are these sequences and why are they starting with 33]?










      share|improve this question















      I found many escape sequences in Bash starting with 33], but what are these sequences and why are they starting with 33]?







      bash ascii






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 14 at 14:22









      pevik

      21317




      21317










      asked Oct 1 '16 at 15:03









      Sessho

      6414




      6414






















          5 Answers
          5






          active

          oldest

          votes


















          22














          The string is actually 33[ and that's not the whole thing.



          After that opening bracket comes a series of numbers and symbols. This string is known as an escape sequence and is used to control the console's cursor and text color, among other things.




          non-printing escape sequences have to be enclosed in [33[ and ]




          If the escape sequence is controlling text color, then it will be followed by an m.



          Here's a table for the color sequences:



          Black       0;30     Dark Gray     1;30  
          Blue 0;34 Light Blue 1;34
          Green 0;32 Light Green 1;32
          Cyan 0;36 Light Cyan 1;36
          Red 0;31 Light Red 1;31
          Purple 0;35 Light Purple 1;35
          Brown 0;33 Yellow 1;33
          Light Gray 0;37 White 1;37


          So, if you want your console prompt to be blue, you would use the following escape sequence (in the filename I'm forgetting):



          [33[34m]


          (Notice the m)



          This escape sequence doesn't only control color, however. It can also control cursor movement. Here's a table/list with the movement codes and how they work:





          • Position the Cursor:



            33[<L>;<C>H


            Or



            33[<L>;<C>f


            puts the cursor at line L and column C.




          • Move the cursor up N lines:



            33[<N>A



          • Move the cursor down N lines:



            33[<N>B



          • Move the cursor forward N columns:



            33[<N>C



          • Move the cursor backward N columns:



            33[<N>D



          • Clear the screen, move to (0,0):



            33[2J



          • Erase to end of line:



            33[K



          • Save cursor position:



            33[s



          • Restore cursor position:



            33[u



          Just be aware that the last two may not work in the terminal emulator you use. Apparently, only xterm and nxterm use those two sequences.



          And example using one of these escape sequences: say I want to position my cursor at line 3, column (character) 9. For that, I would use



          [033[3;9H]


          (I am assuming that column 0 is the first position, so that would be the 8th character).



          Source: http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html (also read 6.2)



          More general reading: http://ascii-table.com/ansi-escape-sequences.php



          Wikipedia: https://en.wikipedia.org/wiki/ANSI_escape_code






          share|improve this answer



















          • 2




            consider also linking to en.wikipedia.org/wiki/ANSI_escape_code
            – cat
            Oct 1 '16 at 16:36






          • 2




            Note that '33' is the ESCAPE character in octal, so it could be given in decimal (27) or hex (0x1B). There are other common ways of writing ESCAPE, e.g. '^[' in shell scripts, "e" in bindkey, etc.
            – jamesqf
            Oct 1 '16 at 19:01






          • 1




            Please note that a number of entries in that table are misleading or inaccurate: bold, faint, underlining etc. can be set and reset independently of color, and are also reset by 0 along with the colors; there's a whole separate set of codes (40–49) for background, and 7 instead swaps foreground and background; ESC[2K erases the entire line both before and after the cursor. A much better source would be the Wikipedia article, or you could go directly to ECMA-48, section 8.3.117 SGR – Select Graphic Rendition.
            – deltab
            Oct 2 '16 at 3:21












          • The phrase "'m' character at the end of each of the following sentences is used as a stop character" on the cplusplus.com post is also a bit confusing, since the table just below contains commands that obviously aren't terminated by an "m". Actually it seems even more misleading here when presented right at the top.
            – ilkkachu
            Oct 2 '16 at 7:43








          • 1




            Technically, the leading 0; in the color sequences is unnecessary. That just makes the background color the default before setting the foreground. You can also set the background with 4x.
            – Nic Hartley
            Oct 2 '16 at 15:31



















          13














          They're control commands for the terminal.



          Terminals were originally rather dumb devices connected to a serial port, and not those fancy multi-tab GUI software with menus we now have. Since they only received a stream of characters (bytes), there was no clear separation between data (what to print on the screen) and commands (how to print it). Instead the commands are represented with special control characters.



          The obvious control characters are stuff like line feed (newline), backspace and bell beep, but more specific commands are given as sequences of characters, starting with the ESC character (code 27 in decimal, 0x1b in hex, or 033 octal). It's often represented as ^[, or 33 as in your example.



          The sequence ESC [ is called the CSI, or Control sequence introducer, and it starts a command with optional numeric parameters, ending in usually a letter that defines the main command. Most of the common escape sequences fall in this class.



          Lists of the escape codes can be found e.g. in the console_codes(4) man page, and on the Wikipedia page for ANSI escape codes.



          Some examples:



          ESC [ 4 A             move cursor 4 lines up (4 can be any number)
          ESC [ 5 B move cursor 5 lines down
          ESC [ 2 K erase current line
          ESC [ 30;46 m set black text (30) on cyan background (46)
          ESC [ 0 m reset color and attributes


          You can test the commands with e.g. Bash. Using the -e flag, the builtin echo command accepts 33 as a representation of the ESC character.



          E.g. this will print a greeting in color in the middle of the screen and another normally in the original cursor position:



          echo -e '33[s33[12;30f33[30;46m  Hello!  33[0m33[uhello'


          The sequence ESC ] which you mentioned is the OSC or Operating System Command, which is mostly used in the command to set the window title in xterm and others, e.g.:



          echo -e '33]0;new window titlea'


          Then there's also ESC ( A (and other letters) that set national character sets on some terminals, to a potentially hilarious effect.






          share|improve this answer































            7














            These are called ANSI escape codes, and they are listed in the man page for console_codes. They are not Bash-specific, but rather work in any console application as long as the terminal supports them (most terminal emulators do).






            share|improve this answer





























              4














              Escape followed by a right square bracket escape] is used to introduce an operating system command (OSC).



              It is in ECMA-48, and you can read a summary of the control sequences used by xterm in XTerm Control Sequences, e.g., for changing the title of the terminal window.



              Escape sequences can begin with different characters. The C1 (8-Bit) Control Characters section in XTerm Control Sequences mentions a few of those: CSI (which you see as escape[, APC, DCS, PM. The reason for the different (second) character is because the pair (escape and ]) is associated with a single-byte control character used for different types of escape sequence.



              If you read through the specification, you will notice that CSI is used for controls with numeric parameters, while OSC allows strings. Beyond just the syntax, the committee which created this standard had in mind uses for APC and PM which differed from DCS and OSC.






              share|improve this answer































                1














                The "escape sequences" described in the other answers are dependent on which terminal TYPE you have (most often "ANSI" or derivates/similar ones).



                $ echo $TERM  
                xterm


                If you wish to write scripts that are (somewhat) INDEPENDENT of the termninal, but still uses e.g. color and other special features, then have a look on the content of man terminfo.



                e.g.



                $ echo -n ".";tput setb 6;tput setf 4;echo -n "test";tput sgr0;echo "."


                will print .test. with test having yellowish background and red foreground color, and this will work for ANY terminal that actually is capable of using colors in the same manner.



                To see what is actually printed, pipe it into od -t x1z as in



                $ tput sgr0 | od -t x1z  
                0000000 1b 28 42 1b 5b 6d >.(B.[m<
                0000006


                ... where the values are show in hexadecimal (due to "x").






                share|improve this answer























                  Your Answer








                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "89"
                  };
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function() {
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled) {
                  StackExchange.using("snippets", function() {
                  createEditor();
                  });
                  }
                  else {
                  createEditor();
                  }
                  });

                  function createEditor() {
                  StackExchange.prepareEditor({
                  heartbeatType: 'answer',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: true,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: 10,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader: {
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  },
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  });


                  }
                  });














                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function () {
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f831971%2fwhat-type-of-sequences-are-escape-sequences-starting-with-033%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  5 Answers
                  5






                  active

                  oldest

                  votes








                  5 Answers
                  5






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  22














                  The string is actually 33[ and that's not the whole thing.



                  After that opening bracket comes a series of numbers and symbols. This string is known as an escape sequence and is used to control the console's cursor and text color, among other things.




                  non-printing escape sequences have to be enclosed in [33[ and ]




                  If the escape sequence is controlling text color, then it will be followed by an m.



                  Here's a table for the color sequences:



                  Black       0;30     Dark Gray     1;30  
                  Blue 0;34 Light Blue 1;34
                  Green 0;32 Light Green 1;32
                  Cyan 0;36 Light Cyan 1;36
                  Red 0;31 Light Red 1;31
                  Purple 0;35 Light Purple 1;35
                  Brown 0;33 Yellow 1;33
                  Light Gray 0;37 White 1;37


                  So, if you want your console prompt to be blue, you would use the following escape sequence (in the filename I'm forgetting):



                  [33[34m]


                  (Notice the m)



                  This escape sequence doesn't only control color, however. It can also control cursor movement. Here's a table/list with the movement codes and how they work:





                  • Position the Cursor:



                    33[<L>;<C>H


                    Or



                    33[<L>;<C>f


                    puts the cursor at line L and column C.




                  • Move the cursor up N lines:



                    33[<N>A



                  • Move the cursor down N lines:



                    33[<N>B



                  • Move the cursor forward N columns:



                    33[<N>C



                  • Move the cursor backward N columns:



                    33[<N>D



                  • Clear the screen, move to (0,0):



                    33[2J



                  • Erase to end of line:



                    33[K



                  • Save cursor position:



                    33[s



                  • Restore cursor position:



                    33[u



                  Just be aware that the last two may not work in the terminal emulator you use. Apparently, only xterm and nxterm use those two sequences.



                  And example using one of these escape sequences: say I want to position my cursor at line 3, column (character) 9. For that, I would use



                  [033[3;9H]


                  (I am assuming that column 0 is the first position, so that would be the 8th character).



                  Source: http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html (also read 6.2)



                  More general reading: http://ascii-table.com/ansi-escape-sequences.php



                  Wikipedia: https://en.wikipedia.org/wiki/ANSI_escape_code






                  share|improve this answer



















                  • 2




                    consider also linking to en.wikipedia.org/wiki/ANSI_escape_code
                    – cat
                    Oct 1 '16 at 16:36






                  • 2




                    Note that '33' is the ESCAPE character in octal, so it could be given in decimal (27) or hex (0x1B). There are other common ways of writing ESCAPE, e.g. '^[' in shell scripts, "e" in bindkey, etc.
                    – jamesqf
                    Oct 1 '16 at 19:01






                  • 1




                    Please note that a number of entries in that table are misleading or inaccurate: bold, faint, underlining etc. can be set and reset independently of color, and are also reset by 0 along with the colors; there's a whole separate set of codes (40–49) for background, and 7 instead swaps foreground and background; ESC[2K erases the entire line both before and after the cursor. A much better source would be the Wikipedia article, or you could go directly to ECMA-48, section 8.3.117 SGR – Select Graphic Rendition.
                    – deltab
                    Oct 2 '16 at 3:21












                  • The phrase "'m' character at the end of each of the following sentences is used as a stop character" on the cplusplus.com post is also a bit confusing, since the table just below contains commands that obviously aren't terminated by an "m". Actually it seems even more misleading here when presented right at the top.
                    – ilkkachu
                    Oct 2 '16 at 7:43








                  • 1




                    Technically, the leading 0; in the color sequences is unnecessary. That just makes the background color the default before setting the foreground. You can also set the background with 4x.
                    – Nic Hartley
                    Oct 2 '16 at 15:31
















                  22














                  The string is actually 33[ and that's not the whole thing.



                  After that opening bracket comes a series of numbers and symbols. This string is known as an escape sequence and is used to control the console's cursor and text color, among other things.




                  non-printing escape sequences have to be enclosed in [33[ and ]




                  If the escape sequence is controlling text color, then it will be followed by an m.



                  Here's a table for the color sequences:



                  Black       0;30     Dark Gray     1;30  
                  Blue 0;34 Light Blue 1;34
                  Green 0;32 Light Green 1;32
                  Cyan 0;36 Light Cyan 1;36
                  Red 0;31 Light Red 1;31
                  Purple 0;35 Light Purple 1;35
                  Brown 0;33 Yellow 1;33
                  Light Gray 0;37 White 1;37


                  So, if you want your console prompt to be blue, you would use the following escape sequence (in the filename I'm forgetting):



                  [33[34m]


                  (Notice the m)



                  This escape sequence doesn't only control color, however. It can also control cursor movement. Here's a table/list with the movement codes and how they work:





                  • Position the Cursor:



                    33[<L>;<C>H


                    Or



                    33[<L>;<C>f


                    puts the cursor at line L and column C.




                  • Move the cursor up N lines:



                    33[<N>A



                  • Move the cursor down N lines:



                    33[<N>B



                  • Move the cursor forward N columns:



                    33[<N>C



                  • Move the cursor backward N columns:



                    33[<N>D



                  • Clear the screen, move to (0,0):



                    33[2J



                  • Erase to end of line:



                    33[K



                  • Save cursor position:



                    33[s



                  • Restore cursor position:



                    33[u



                  Just be aware that the last two may not work in the terminal emulator you use. Apparently, only xterm and nxterm use those two sequences.



                  And example using one of these escape sequences: say I want to position my cursor at line 3, column (character) 9. For that, I would use



                  [033[3;9H]


                  (I am assuming that column 0 is the first position, so that would be the 8th character).



                  Source: http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html (also read 6.2)



                  More general reading: http://ascii-table.com/ansi-escape-sequences.php



                  Wikipedia: https://en.wikipedia.org/wiki/ANSI_escape_code






                  share|improve this answer



















                  • 2




                    consider also linking to en.wikipedia.org/wiki/ANSI_escape_code
                    – cat
                    Oct 1 '16 at 16:36






                  • 2




                    Note that '33' is the ESCAPE character in octal, so it could be given in decimal (27) or hex (0x1B). There are other common ways of writing ESCAPE, e.g. '^[' in shell scripts, "e" in bindkey, etc.
                    – jamesqf
                    Oct 1 '16 at 19:01






                  • 1




                    Please note that a number of entries in that table are misleading or inaccurate: bold, faint, underlining etc. can be set and reset independently of color, and are also reset by 0 along with the colors; there's a whole separate set of codes (40–49) for background, and 7 instead swaps foreground and background; ESC[2K erases the entire line both before and after the cursor. A much better source would be the Wikipedia article, or you could go directly to ECMA-48, section 8.3.117 SGR – Select Graphic Rendition.
                    – deltab
                    Oct 2 '16 at 3:21












                  • The phrase "'m' character at the end of each of the following sentences is used as a stop character" on the cplusplus.com post is also a bit confusing, since the table just below contains commands that obviously aren't terminated by an "m". Actually it seems even more misleading here when presented right at the top.
                    – ilkkachu
                    Oct 2 '16 at 7:43








                  • 1




                    Technically, the leading 0; in the color sequences is unnecessary. That just makes the background color the default before setting the foreground. You can also set the background with 4x.
                    – Nic Hartley
                    Oct 2 '16 at 15:31














                  22












                  22








                  22






                  The string is actually 33[ and that's not the whole thing.



                  After that opening bracket comes a series of numbers and symbols. This string is known as an escape sequence and is used to control the console's cursor and text color, among other things.




                  non-printing escape sequences have to be enclosed in [33[ and ]




                  If the escape sequence is controlling text color, then it will be followed by an m.



                  Here's a table for the color sequences:



                  Black       0;30     Dark Gray     1;30  
                  Blue 0;34 Light Blue 1;34
                  Green 0;32 Light Green 1;32
                  Cyan 0;36 Light Cyan 1;36
                  Red 0;31 Light Red 1;31
                  Purple 0;35 Light Purple 1;35
                  Brown 0;33 Yellow 1;33
                  Light Gray 0;37 White 1;37


                  So, if you want your console prompt to be blue, you would use the following escape sequence (in the filename I'm forgetting):



                  [33[34m]


                  (Notice the m)



                  This escape sequence doesn't only control color, however. It can also control cursor movement. Here's a table/list with the movement codes and how they work:





                  • Position the Cursor:



                    33[<L>;<C>H


                    Or



                    33[<L>;<C>f


                    puts the cursor at line L and column C.




                  • Move the cursor up N lines:



                    33[<N>A



                  • Move the cursor down N lines:



                    33[<N>B



                  • Move the cursor forward N columns:



                    33[<N>C



                  • Move the cursor backward N columns:



                    33[<N>D



                  • Clear the screen, move to (0,0):



                    33[2J



                  • Erase to end of line:



                    33[K



                  • Save cursor position:



                    33[s



                  • Restore cursor position:



                    33[u



                  Just be aware that the last two may not work in the terminal emulator you use. Apparently, only xterm and nxterm use those two sequences.



                  And example using one of these escape sequences: say I want to position my cursor at line 3, column (character) 9. For that, I would use



                  [033[3;9H]


                  (I am assuming that column 0 is the first position, so that would be the 8th character).



                  Source: http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html (also read 6.2)



                  More general reading: http://ascii-table.com/ansi-escape-sequences.php



                  Wikipedia: https://en.wikipedia.org/wiki/ANSI_escape_code






                  share|improve this answer














                  The string is actually 33[ and that's not the whole thing.



                  After that opening bracket comes a series of numbers and symbols. This string is known as an escape sequence and is used to control the console's cursor and text color, among other things.




                  non-printing escape sequences have to be enclosed in [33[ and ]




                  If the escape sequence is controlling text color, then it will be followed by an m.



                  Here's a table for the color sequences:



                  Black       0;30     Dark Gray     1;30  
                  Blue 0;34 Light Blue 1;34
                  Green 0;32 Light Green 1;32
                  Cyan 0;36 Light Cyan 1;36
                  Red 0;31 Light Red 1;31
                  Purple 0;35 Light Purple 1;35
                  Brown 0;33 Yellow 1;33
                  Light Gray 0;37 White 1;37


                  So, if you want your console prompt to be blue, you would use the following escape sequence (in the filename I'm forgetting):



                  [33[34m]


                  (Notice the m)



                  This escape sequence doesn't only control color, however. It can also control cursor movement. Here's a table/list with the movement codes and how they work:





                  • Position the Cursor:



                    33[<L>;<C>H


                    Or



                    33[<L>;<C>f


                    puts the cursor at line L and column C.




                  • Move the cursor up N lines:



                    33[<N>A



                  • Move the cursor down N lines:



                    33[<N>B



                  • Move the cursor forward N columns:



                    33[<N>C



                  • Move the cursor backward N columns:



                    33[<N>D



                  • Clear the screen, move to (0,0):



                    33[2J



                  • Erase to end of line:



                    33[K



                  • Save cursor position:



                    33[s



                  • Restore cursor position:



                    33[u



                  Just be aware that the last two may not work in the terminal emulator you use. Apparently, only xterm and nxterm use those two sequences.



                  And example using one of these escape sequences: say I want to position my cursor at line 3, column (character) 9. For that, I would use



                  [033[3;9H]


                  (I am assuming that column 0 is the first position, so that would be the 8th character).



                  Source: http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html (also read 6.2)



                  More general reading: http://ascii-table.com/ansi-escape-sequences.php



                  Wikipedia: https://en.wikipedia.org/wiki/ANSI_escape_code







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Oct 2 '16 at 15:28









                  muru

                  1




                  1










                  answered Oct 1 '16 at 15:12









                  TheWanderer

                  16k113657




                  16k113657








                  • 2




                    consider also linking to en.wikipedia.org/wiki/ANSI_escape_code
                    – cat
                    Oct 1 '16 at 16:36






                  • 2




                    Note that '33' is the ESCAPE character in octal, so it could be given in decimal (27) or hex (0x1B). There are other common ways of writing ESCAPE, e.g. '^[' in shell scripts, "e" in bindkey, etc.
                    – jamesqf
                    Oct 1 '16 at 19:01






                  • 1




                    Please note that a number of entries in that table are misleading or inaccurate: bold, faint, underlining etc. can be set and reset independently of color, and are also reset by 0 along with the colors; there's a whole separate set of codes (40–49) for background, and 7 instead swaps foreground and background; ESC[2K erases the entire line both before and after the cursor. A much better source would be the Wikipedia article, or you could go directly to ECMA-48, section 8.3.117 SGR – Select Graphic Rendition.
                    – deltab
                    Oct 2 '16 at 3:21












                  • The phrase "'m' character at the end of each of the following sentences is used as a stop character" on the cplusplus.com post is also a bit confusing, since the table just below contains commands that obviously aren't terminated by an "m". Actually it seems even more misleading here when presented right at the top.
                    – ilkkachu
                    Oct 2 '16 at 7:43








                  • 1




                    Technically, the leading 0; in the color sequences is unnecessary. That just makes the background color the default before setting the foreground. You can also set the background with 4x.
                    – Nic Hartley
                    Oct 2 '16 at 15:31














                  • 2




                    consider also linking to en.wikipedia.org/wiki/ANSI_escape_code
                    – cat
                    Oct 1 '16 at 16:36






                  • 2




                    Note that '33' is the ESCAPE character in octal, so it could be given in decimal (27) or hex (0x1B). There are other common ways of writing ESCAPE, e.g. '^[' in shell scripts, "e" in bindkey, etc.
                    – jamesqf
                    Oct 1 '16 at 19:01






                  • 1




                    Please note that a number of entries in that table are misleading or inaccurate: bold, faint, underlining etc. can be set and reset independently of color, and are also reset by 0 along with the colors; there's a whole separate set of codes (40–49) for background, and 7 instead swaps foreground and background; ESC[2K erases the entire line both before and after the cursor. A much better source would be the Wikipedia article, or you could go directly to ECMA-48, section 8.3.117 SGR – Select Graphic Rendition.
                    – deltab
                    Oct 2 '16 at 3:21












                  • The phrase "'m' character at the end of each of the following sentences is used as a stop character" on the cplusplus.com post is also a bit confusing, since the table just below contains commands that obviously aren't terminated by an "m". Actually it seems even more misleading here when presented right at the top.
                    – ilkkachu
                    Oct 2 '16 at 7:43








                  • 1




                    Technically, the leading 0; in the color sequences is unnecessary. That just makes the background color the default before setting the foreground. You can also set the background with 4x.
                    – Nic Hartley
                    Oct 2 '16 at 15:31








                  2




                  2




                  consider also linking to en.wikipedia.org/wiki/ANSI_escape_code
                  – cat
                  Oct 1 '16 at 16:36




                  consider also linking to en.wikipedia.org/wiki/ANSI_escape_code
                  – cat
                  Oct 1 '16 at 16:36




                  2




                  2




                  Note that '33' is the ESCAPE character in octal, so it could be given in decimal (27) or hex (0x1B). There are other common ways of writing ESCAPE, e.g. '^[' in shell scripts, "e" in bindkey, etc.
                  – jamesqf
                  Oct 1 '16 at 19:01




                  Note that '33' is the ESCAPE character in octal, so it could be given in decimal (27) or hex (0x1B). There are other common ways of writing ESCAPE, e.g. '^[' in shell scripts, "e" in bindkey, etc.
                  – jamesqf
                  Oct 1 '16 at 19:01




                  1




                  1




                  Please note that a number of entries in that table are misleading or inaccurate: bold, faint, underlining etc. can be set and reset independently of color, and are also reset by 0 along with the colors; there's a whole separate set of codes (40–49) for background, and 7 instead swaps foreground and background; ESC[2K erases the entire line both before and after the cursor. A much better source would be the Wikipedia article, or you could go directly to ECMA-48, section 8.3.117 SGR – Select Graphic Rendition.
                  – deltab
                  Oct 2 '16 at 3:21






                  Please note that a number of entries in that table are misleading or inaccurate: bold, faint, underlining etc. can be set and reset independently of color, and are also reset by 0 along with the colors; there's a whole separate set of codes (40–49) for background, and 7 instead swaps foreground and background; ESC[2K erases the entire line both before and after the cursor. A much better source would be the Wikipedia article, or you could go directly to ECMA-48, section 8.3.117 SGR – Select Graphic Rendition.
                  – deltab
                  Oct 2 '16 at 3:21














                  The phrase "'m' character at the end of each of the following sentences is used as a stop character" on the cplusplus.com post is also a bit confusing, since the table just below contains commands that obviously aren't terminated by an "m". Actually it seems even more misleading here when presented right at the top.
                  – ilkkachu
                  Oct 2 '16 at 7:43






                  The phrase "'m' character at the end of each of the following sentences is used as a stop character" on the cplusplus.com post is also a bit confusing, since the table just below contains commands that obviously aren't terminated by an "m". Actually it seems even more misleading here when presented right at the top.
                  – ilkkachu
                  Oct 2 '16 at 7:43






                  1




                  1




                  Technically, the leading 0; in the color sequences is unnecessary. That just makes the background color the default before setting the foreground. You can also set the background with 4x.
                  – Nic Hartley
                  Oct 2 '16 at 15:31




                  Technically, the leading 0; in the color sequences is unnecessary. That just makes the background color the default before setting the foreground. You can also set the background with 4x.
                  – Nic Hartley
                  Oct 2 '16 at 15:31













                  13














                  They're control commands for the terminal.



                  Terminals were originally rather dumb devices connected to a serial port, and not those fancy multi-tab GUI software with menus we now have. Since they only received a stream of characters (bytes), there was no clear separation between data (what to print on the screen) and commands (how to print it). Instead the commands are represented with special control characters.



                  The obvious control characters are stuff like line feed (newline), backspace and bell beep, but more specific commands are given as sequences of characters, starting with the ESC character (code 27 in decimal, 0x1b in hex, or 033 octal). It's often represented as ^[, or 33 as in your example.



                  The sequence ESC [ is called the CSI, or Control sequence introducer, and it starts a command with optional numeric parameters, ending in usually a letter that defines the main command. Most of the common escape sequences fall in this class.



                  Lists of the escape codes can be found e.g. in the console_codes(4) man page, and on the Wikipedia page for ANSI escape codes.



                  Some examples:



                  ESC [ 4 A             move cursor 4 lines up (4 can be any number)
                  ESC [ 5 B move cursor 5 lines down
                  ESC [ 2 K erase current line
                  ESC [ 30;46 m set black text (30) on cyan background (46)
                  ESC [ 0 m reset color and attributes


                  You can test the commands with e.g. Bash. Using the -e flag, the builtin echo command accepts 33 as a representation of the ESC character.



                  E.g. this will print a greeting in color in the middle of the screen and another normally in the original cursor position:



                  echo -e '33[s33[12;30f33[30;46m  Hello!  33[0m33[uhello'


                  The sequence ESC ] which you mentioned is the OSC or Operating System Command, which is mostly used in the command to set the window title in xterm and others, e.g.:



                  echo -e '33]0;new window titlea'


                  Then there's also ESC ( A (and other letters) that set national character sets on some terminals, to a potentially hilarious effect.






                  share|improve this answer




























                    13














                    They're control commands for the terminal.



                    Terminals were originally rather dumb devices connected to a serial port, and not those fancy multi-tab GUI software with menus we now have. Since they only received a stream of characters (bytes), there was no clear separation between data (what to print on the screen) and commands (how to print it). Instead the commands are represented with special control characters.



                    The obvious control characters are stuff like line feed (newline), backspace and bell beep, but more specific commands are given as sequences of characters, starting with the ESC character (code 27 in decimal, 0x1b in hex, or 033 octal). It's often represented as ^[, or 33 as in your example.



                    The sequence ESC [ is called the CSI, or Control sequence introducer, and it starts a command with optional numeric parameters, ending in usually a letter that defines the main command. Most of the common escape sequences fall in this class.



                    Lists of the escape codes can be found e.g. in the console_codes(4) man page, and on the Wikipedia page for ANSI escape codes.



                    Some examples:



                    ESC [ 4 A             move cursor 4 lines up (4 can be any number)
                    ESC [ 5 B move cursor 5 lines down
                    ESC [ 2 K erase current line
                    ESC [ 30;46 m set black text (30) on cyan background (46)
                    ESC [ 0 m reset color and attributes


                    You can test the commands with e.g. Bash. Using the -e flag, the builtin echo command accepts 33 as a representation of the ESC character.



                    E.g. this will print a greeting in color in the middle of the screen and another normally in the original cursor position:



                    echo -e '33[s33[12;30f33[30;46m  Hello!  33[0m33[uhello'


                    The sequence ESC ] which you mentioned is the OSC or Operating System Command, which is mostly used in the command to set the window title in xterm and others, e.g.:



                    echo -e '33]0;new window titlea'


                    Then there's also ESC ( A (and other letters) that set national character sets on some terminals, to a potentially hilarious effect.






                    share|improve this answer


























                      13












                      13








                      13






                      They're control commands for the terminal.



                      Terminals were originally rather dumb devices connected to a serial port, and not those fancy multi-tab GUI software with menus we now have. Since they only received a stream of characters (bytes), there was no clear separation between data (what to print on the screen) and commands (how to print it). Instead the commands are represented with special control characters.



                      The obvious control characters are stuff like line feed (newline), backspace and bell beep, but more specific commands are given as sequences of characters, starting with the ESC character (code 27 in decimal, 0x1b in hex, or 033 octal). It's often represented as ^[, or 33 as in your example.



                      The sequence ESC [ is called the CSI, or Control sequence introducer, and it starts a command with optional numeric parameters, ending in usually a letter that defines the main command. Most of the common escape sequences fall in this class.



                      Lists of the escape codes can be found e.g. in the console_codes(4) man page, and on the Wikipedia page for ANSI escape codes.



                      Some examples:



                      ESC [ 4 A             move cursor 4 lines up (4 can be any number)
                      ESC [ 5 B move cursor 5 lines down
                      ESC [ 2 K erase current line
                      ESC [ 30;46 m set black text (30) on cyan background (46)
                      ESC [ 0 m reset color and attributes


                      You can test the commands with e.g. Bash. Using the -e flag, the builtin echo command accepts 33 as a representation of the ESC character.



                      E.g. this will print a greeting in color in the middle of the screen and another normally in the original cursor position:



                      echo -e '33[s33[12;30f33[30;46m  Hello!  33[0m33[uhello'


                      The sequence ESC ] which you mentioned is the OSC or Operating System Command, which is mostly used in the command to set the window title in xterm and others, e.g.:



                      echo -e '33]0;new window titlea'


                      Then there's also ESC ( A (and other letters) that set national character sets on some terminals, to a potentially hilarious effect.






                      share|improve this answer














                      They're control commands for the terminal.



                      Terminals were originally rather dumb devices connected to a serial port, and not those fancy multi-tab GUI software with menus we now have. Since they only received a stream of characters (bytes), there was no clear separation between data (what to print on the screen) and commands (how to print it). Instead the commands are represented with special control characters.



                      The obvious control characters are stuff like line feed (newline), backspace and bell beep, but more specific commands are given as sequences of characters, starting with the ESC character (code 27 in decimal, 0x1b in hex, or 033 octal). It's often represented as ^[, or 33 as in your example.



                      The sequence ESC [ is called the CSI, or Control sequence introducer, and it starts a command with optional numeric parameters, ending in usually a letter that defines the main command. Most of the common escape sequences fall in this class.



                      Lists of the escape codes can be found e.g. in the console_codes(4) man page, and on the Wikipedia page for ANSI escape codes.



                      Some examples:



                      ESC [ 4 A             move cursor 4 lines up (4 can be any number)
                      ESC [ 5 B move cursor 5 lines down
                      ESC [ 2 K erase current line
                      ESC [ 30;46 m set black text (30) on cyan background (46)
                      ESC [ 0 m reset color and attributes


                      You can test the commands with e.g. Bash. Using the -e flag, the builtin echo command accepts 33 as a representation of the ESC character.



                      E.g. this will print a greeting in color in the middle of the screen and another normally in the original cursor position:



                      echo -e '33[s33[12;30f33[30;46m  Hello!  33[0m33[uhello'


                      The sequence ESC ] which you mentioned is the OSC or Operating System Command, which is mostly used in the command to set the window title in xterm and others, e.g.:



                      echo -e '33]0;new window titlea'


                      Then there's also ESC ( A (and other letters) that set national character sets on some terminals, to a potentially hilarious effect.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Apr 13 '17 at 12:37









                      Community

                      1




                      1










                      answered Oct 1 '16 at 21:35









                      ilkkachu

                      1,031210




                      1,031210























                          7














                          These are called ANSI escape codes, and they are listed in the man page for console_codes. They are not Bash-specific, but rather work in any console application as long as the terminal supports them (most terminal emulators do).






                          share|improve this answer


























                            7














                            These are called ANSI escape codes, and they are listed in the man page for console_codes. They are not Bash-specific, but rather work in any console application as long as the terminal supports them (most terminal emulators do).






                            share|improve this answer
























                              7












                              7








                              7






                              These are called ANSI escape codes, and they are listed in the man page for console_codes. They are not Bash-specific, but rather work in any console application as long as the terminal supports them (most terminal emulators do).






                              share|improve this answer












                              These are called ANSI escape codes, and they are listed in the man page for console_codes. They are not Bash-specific, but rather work in any console application as long as the terminal supports them (most terminal emulators do).







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Oct 1 '16 at 17:46









                              Joey Marianer

                              21711




                              21711























                                  4














                                  Escape followed by a right square bracket escape] is used to introduce an operating system command (OSC).



                                  It is in ECMA-48, and you can read a summary of the control sequences used by xterm in XTerm Control Sequences, e.g., for changing the title of the terminal window.



                                  Escape sequences can begin with different characters. The C1 (8-Bit) Control Characters section in XTerm Control Sequences mentions a few of those: CSI (which you see as escape[, APC, DCS, PM. The reason for the different (second) character is because the pair (escape and ]) is associated with a single-byte control character used for different types of escape sequence.



                                  If you read through the specification, you will notice that CSI is used for controls with numeric parameters, while OSC allows strings. Beyond just the syntax, the committee which created this standard had in mind uses for APC and PM which differed from DCS and OSC.






                                  share|improve this answer




























                                    4














                                    Escape followed by a right square bracket escape] is used to introduce an operating system command (OSC).



                                    It is in ECMA-48, and you can read a summary of the control sequences used by xterm in XTerm Control Sequences, e.g., for changing the title of the terminal window.



                                    Escape sequences can begin with different characters. The C1 (8-Bit) Control Characters section in XTerm Control Sequences mentions a few of those: CSI (which you see as escape[, APC, DCS, PM. The reason for the different (second) character is because the pair (escape and ]) is associated with a single-byte control character used for different types of escape sequence.



                                    If you read through the specification, you will notice that CSI is used for controls with numeric parameters, while OSC allows strings. Beyond just the syntax, the committee which created this standard had in mind uses for APC and PM which differed from DCS and OSC.






                                    share|improve this answer


























                                      4












                                      4








                                      4






                                      Escape followed by a right square bracket escape] is used to introduce an operating system command (OSC).



                                      It is in ECMA-48, and you can read a summary of the control sequences used by xterm in XTerm Control Sequences, e.g., for changing the title of the terminal window.



                                      Escape sequences can begin with different characters. The C1 (8-Bit) Control Characters section in XTerm Control Sequences mentions a few of those: CSI (which you see as escape[, APC, DCS, PM. The reason for the different (second) character is because the pair (escape and ]) is associated with a single-byte control character used for different types of escape sequence.



                                      If you read through the specification, you will notice that CSI is used for controls with numeric parameters, while OSC allows strings. Beyond just the syntax, the committee which created this standard had in mind uses for APC and PM which differed from DCS and OSC.






                                      share|improve this answer














                                      Escape followed by a right square bracket escape] is used to introduce an operating system command (OSC).



                                      It is in ECMA-48, and you can read a summary of the control sequences used by xterm in XTerm Control Sequences, e.g., for changing the title of the terminal window.



                                      Escape sequences can begin with different characters. The C1 (8-Bit) Control Characters section in XTerm Control Sequences mentions a few of those: CSI (which you see as escape[, APC, DCS, PM. The reason for the different (second) character is because the pair (escape and ]) is associated with a single-byte control character used for different types of escape sequence.



                                      If you read through the specification, you will notice that CSI is used for controls with numeric parameters, while OSC allows strings. Beyond just the syntax, the committee which created this standard had in mind uses for APC and PM which differed from DCS and OSC.







                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Feb 23 '17 at 8:31









                                      Tobias Kienzler

                                      3011521




                                      3011521










                                      answered Oct 2 '16 at 23:11









                                      Thomas Dickey

                                      1664




                                      1664























                                          1














                                          The "escape sequences" described in the other answers are dependent on which terminal TYPE you have (most often "ANSI" or derivates/similar ones).



                                          $ echo $TERM  
                                          xterm


                                          If you wish to write scripts that are (somewhat) INDEPENDENT of the termninal, but still uses e.g. color and other special features, then have a look on the content of man terminfo.



                                          e.g.



                                          $ echo -n ".";tput setb 6;tput setf 4;echo -n "test";tput sgr0;echo "."


                                          will print .test. with test having yellowish background and red foreground color, and this will work for ANY terminal that actually is capable of using colors in the same manner.



                                          To see what is actually printed, pipe it into od -t x1z as in



                                          $ tput sgr0 | od -t x1z  
                                          0000000 1b 28 42 1b 5b 6d >.(B.[m<
                                          0000006


                                          ... where the values are show in hexadecimal (due to "x").






                                          share|improve this answer




























                                            1














                                            The "escape sequences" described in the other answers are dependent on which terminal TYPE you have (most often "ANSI" or derivates/similar ones).



                                            $ echo $TERM  
                                            xterm


                                            If you wish to write scripts that are (somewhat) INDEPENDENT of the termninal, but still uses e.g. color and other special features, then have a look on the content of man terminfo.



                                            e.g.



                                            $ echo -n ".";tput setb 6;tput setf 4;echo -n "test";tput sgr0;echo "."


                                            will print .test. with test having yellowish background and red foreground color, and this will work for ANY terminal that actually is capable of using colors in the same manner.



                                            To see what is actually printed, pipe it into od -t x1z as in



                                            $ tput sgr0 | od -t x1z  
                                            0000000 1b 28 42 1b 5b 6d >.(B.[m<
                                            0000006


                                            ... where the values are show in hexadecimal (due to "x").






                                            share|improve this answer


























                                              1












                                              1








                                              1






                                              The "escape sequences" described in the other answers are dependent on which terminal TYPE you have (most often "ANSI" or derivates/similar ones).



                                              $ echo $TERM  
                                              xterm


                                              If you wish to write scripts that are (somewhat) INDEPENDENT of the termninal, but still uses e.g. color and other special features, then have a look on the content of man terminfo.



                                              e.g.



                                              $ echo -n ".";tput setb 6;tput setf 4;echo -n "test";tput sgr0;echo "."


                                              will print .test. with test having yellowish background and red foreground color, and this will work for ANY terminal that actually is capable of using colors in the same manner.



                                              To see what is actually printed, pipe it into od -t x1z as in



                                              $ tput sgr0 | od -t x1z  
                                              0000000 1b 28 42 1b 5b 6d >.(B.[m<
                                              0000006


                                              ... where the values are show in hexadecimal (due to "x").






                                              share|improve this answer














                                              The "escape sequences" described in the other answers are dependent on which terminal TYPE you have (most often "ANSI" or derivates/similar ones).



                                              $ echo $TERM  
                                              xterm


                                              If you wish to write scripts that are (somewhat) INDEPENDENT of the termninal, but still uses e.g. color and other special features, then have a look on the content of man terminfo.



                                              e.g.



                                              $ echo -n ".";tput setb 6;tput setf 4;echo -n "test";tput sgr0;echo "."


                                              will print .test. with test having yellowish background and red foreground color, and this will work for ANY terminal that actually is capable of using colors in the same manner.



                                              To see what is actually printed, pipe it into od -t x1z as in



                                              $ tput sgr0 | od -t x1z  
                                              0000000 1b 28 42 1b 5b 6d >.(B.[m<
                                              0000006


                                              ... where the values are show in hexadecimal (due to "x").







                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited Oct 2 '16 at 15:25









                                              muru

                                              1




                                              1










                                              answered Oct 2 '16 at 14:06









                                              Hannu

                                              2,1781125




                                              2,1781125






























                                                  draft saved

                                                  draft discarded




















































                                                  Thanks for contributing an answer to Ask Ubuntu!


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid



                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                  To learn more, see our tips on writing great answers.





                                                  Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                  Please pay close attention to the following guidance:


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid



                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                  To learn more, see our tips on writing great answers.




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function () {
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f831971%2fwhat-type-of-sequences-are-escape-sequences-starting-with-033%23new-answer', 'question_page');
                                                  }
                                                  );

                                                  Post as a guest















                                                  Required, but never shown





















































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown

































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown







                                                  Popular posts from this blog

                                                  數位音樂下載

                                                  When can things happen in Etherscan, such as the picture below?

                                                  格利澤436b