Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
ANSI escape code
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== In shell scripting === ANSI escape codes are often used in [[UNIX]] and UNIX-like [[virtual console|terminals]] to provide [[syntax highlighting]]. For example, on compatible terminals, the following ''[[ls|list]]'' command color-codes file and directory names by type. ls --color Users can employ escape codes in their scripts by including them as part of ''[[standard output]]'' or ''[[stderr|standard error]]''. For example, the following GNU ''[[sed]]'' command embellishes the output of the ''[[make (software)|make]]'' command by displaying lines containing words starting with "WARN" in [[reverse video]] and words starting with "ERR" in bright yellow on a dark red background ([[letter case]] is ignored). The representations of the codes are highlighted.<ref>{{cite web |url=http://www.debian.org/doc/manuals/debian-reference/ch09.en.html#_colorized_shell_echo |title=Chapter 9. System tips|work=debian.org}}</ref> <span style="white-space:pre-wrap;">make 2>&1 | sed -e 's/.*\bWARN.*/<span style="border:1px solid grey;border-radius:5px;color:white;background:black;font-weight:bolder;">\x1b[7m</span>&<span style="border:1px solid grey;border-radius:5px;">\x1b[0m</span>/i' -e 's/.*\bERR.*/<span style="border:1px solid grey;border-radius:5px;color:yellow;background:maroon;font-weight:bolder;">\x1b[93;41m</span>&<span style="border:1px solid grey;border-radius:5px;">\x1b[0m</span>/i'</span> The following [[Bash (Unix shell)|Bash]] function flashes the terminal (by alternately sending reverse and normal video mode codes) until the user presses a key.<ref>{{cite web |title=VT100.net: Digital VT100 User Guide |url=http://vt100.net/docs/vt100-ug/chapter3.html |access-date=2015-01-19}}</ref> flasher () { while true; do printf <span style="border:1px solid grey;border-radius:5px;color:white;background:black;font-weight:bolder;">\\e[?5h</span>; sleep 0.1; printf <span style="border:1px solid grey;border-radius:5px;font-weight:bolder;">\\e[?5l</span>; read -s -n1 -t1 && break; done; } This can be used to alert a programmer when a lengthy command terminates, such as with {{code|make ; flasher}}{{thin space}}.<ref>{{cite web |title=bash β How to get a notification when my commands are done β Ask Different |url=http://apple.stackexchange.com/questions/9412/how-to-get-a-notification-when-my-commands-are-done |access-date=2015-01-19}}</ref> printf \\033c This will reset the console, similar to the command {{code|reset}} on modern Linux systems; however it should work even on older Linux systems and on other (non-Linux) UNIX variants.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
ANSI escape code
(section)
Add topic