Tag Info

Hot answers tagged

18

You can use tput reset. Besides reset and tput reset you can use following shell script. #!/bin/sh echo -e \\033c This sends control characters Esc-C to the console which resets the terminal. Google Keywords: Linux Console Control Sequences man console_codes says: The sequence ESC c causes a terminal reset, which is what you want if the screen ...


17

Find where your PS1 is set in your .bashrc and insert '\[\e[1m\]' at the beginning and \[\e[0m\] at the end. \[ and \] are necessary so the shell knows the mess inside takes up 0 space on the screen, which prevents some screwed up behavior when doing line-editing. You don't need to worry too much about it. \e[ is known as the CSI (control sequence ...


16

The following script should filter out all ANSI/VT100/xterm control sequences for (based on ctlseqs). Minimally tested, please report any under- or over-match. #!/usr/bin/env perl while (<>) { s/ \e[ #%()*+\-.\/]. | (?:\e\[|\x9b) [ -?]* [@-~] | # CSI ... Cmd (?:\e\]|\x9d) .*? (?:\e\\|[\a\x9c]) | # OSC ... (ST|BEL) ...


14

Many programs that generate colored output detect if they're writing to a TTY, and switch off colors if they aren't. This is because color codes are annoying when you only want to capture the text, so they try to "do the right thing" automatically. The simplest way to capture color output from a program like that is to tell it to write color even though ...


14

That's the way that the terminal represents the raw keycode of the Up key sent to it by the keyboard. Basically, your shell would normally intercept the keypress, but there's nothing to do that at the login prompt. So the character that you typed gets printed to the console just like any other letter (or number, or whatever).


10

This snippet is used to print out the hostname of the system with a blue background and a green font. To color your shell, you use special color escape sequences. \e[ starts the color scheme, 32; will set the foreground color to green, 44 will set the background color to blue and m will end it. $(command) creates a new shell, executes command and returns ...


10

There is escape char in ssh, by default this is tilde ~. It is recognized only at the beggining of a line. To suspend your ssh session type ~ then Ctrl+Z. Refer to the ssh(1) manual under ESCAPE CHARACTERS for more information.


9

There are three kinds of escape codes in there: bash parameter expansion, bash prompt expansion, and terminal escape codes. ${debian_chroot:+($debian_chroot)} means “if $debian_chroot is set and non-empty, then ($debian_chroot), else nothing”. (See /etc/bash.bashrc for how debian_chroot is defined. As the name indicates this is a Debian thing.) The ...


9

VT100 terminals (which all modern terminal emulators emulate to some extent) supported a number of problematic commands, but modern emulators or distributions disable the more problematic and less useful ones. Here's a non-exhaustive list of potentially risky escape sequences (not including the ones that merely make the display unreadable in some way): The ...


9

The behavior of echo varies from shell to shell¹; printf's behavior is more standard. printf "Hi\nabcd" >> ab.txt ¹ "It is not possible to use echo portably across all POSIX systems unless both -n (as the first argument) and escape sequences are omitted."


8

That seems to be the good old form feed character, described in man ascii as: Oct Dec Hex Char ------------------------------------------ 014 12 0C FF '\f' (form feed) (Not mentioned there, but ^L's code is the same 12.) Then in bash any of these should work: grep -v $'^\f' file grep -v $'^\cL' file grep -v $'\x0C' file


8

Updating Gilles' answer to also remove carriage returns and do backspace-erasing of previous characters, which were both important to me for a typescript generated on Cygwin: #!/usr/bin/perl while (<>) { s/ \e[ #%()*+\-.\/]. | \r | # Remove extra carriage returns also (?:\e\[|\x9b) [ -?]* [@-~] | # CSI ... Cmd (?:\e\]|\x9d) ...


8

You need to use declare -A instead of declare -a. You are clearly using associative arrays with arbitrary string arguments as indices, but declare -a is only for integer indexed arrays. arg.txt does not evaluate to a valid integer, hence your error. Edit You seem to be using bash version 3. Unfortunately, associative arrays are not available until ...


8

You could try URL-encoding your password. @ should be replaced by %40. Tackling Special Characters in Proxy Passwords on Linux indicates this should work, but looking around other people seem not to get that to work (and I have no way of testing this).


8

Keyboards send events to the computer. An event says “scan code nnn down” or “scan code nnn up”. At the other end of the chain, applications running in a terminal expect input in the form of a sequence of characters. (Unless they've requested raw access, like the X server does.) When you press A, the keyboard sends the information “scan code 38 down”. The ...


7

You should quote both the declaration and the usage PATH="/var/root/Documents/MyFile OG-v1.2.3.pkg" scp "$PATH" Me@10.1.10.33:/Users/Me/Desktop If you do not quote the first, $PATH will contain just the first part. If you do not quote the second, scp will treat each space-separated part as an argument.


7

Because you used sh, not bash, then echo command in sh doesn't have option -e. From sh manpage: echo [-n] args... Print the arguments on the standard output, separated by spaces. Unless the -n option is present, a newline is output following the arguments. And it doesn't have \e, too: If any of the following ...


6

infocmp can help. It writes escape as \E rather than \e or ^[. For example, to find \e[A, which is your history-search-backward: $ infocmp -1x | grep -F '=\E[A,' cuu1=\E[A, $ man 5 terminfo | grep ' cuu1 ' cursor_up cuu1 up up one line Which tells you to press cursor up, a.k.a. up arrow. Note that you ...


6

You can use the following string literal syntax: $ echo $'\'single quote phrase\' "double quote phrase"' 'single quote phrase' "double quote phrase" From man bash Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard. Backslash ...


6

\033 is the octal code for the Esc (Escape) character, which is a good hint that the echoed strings in your PROMPT_COMMAND are terminal control sequences. Both sequences in your examples look like they set the terminal title to user@host:pwd. The first case, xterm* sets the window name and icon title. For a detailed explanation, look at the list of xterm ...


6

You should be able to do this by setting the PS1 prompt variable in your ~/.bashrc file like this: PS1='[\u@\h \w]\$ ' To make it colored (and possibly bold - this depends on whether your terminal emulator has enabled it) you need to add escape color codes: PS1='\[\e[1;91m\][\u@\h \w]\$\[\e[0m\] ' Here, everything not being escaped between the 1;91m ...


6

VT100s responded to character sequences sent to them as output. So echo'ing characters works because the terminal sees it as output. Typing characters is input; the terminal will respond only if the characters are echoed by the receiving computer. Your typical shell doesn't echo ESC, it interprets ESC as the prefix for some interactive input command. Run ...


6

Single quotes are terminated by single quotes, all other characters in between (including backslashes) are ignored. Suggestion: avoid find+xargs when grep -r pattern . can recursively grep on the current directory. The below commands have equivalent behavior: grep -rns "add_action('save_post'," . grep -rns 'add_action('\'save_post\', . The last command ...


6

-e is not POSIX (in fact, POSIX echo generally accepts no options (though is allowed to support -n), see here), and /bin/sh on your system appears to be a POSIX shell. -e is an extension accepted in some shells, but you shouldn't rely on it, it's not portable. Ideally, use printf, or switch to using a shell which has echo -e. Also see the caveats of \e in ...


6

If you look at tar's manpage, you'll see: -X, --exclude-from FILE exclude patterns listed in FILE The info doc gives further details. So list needs to be a list of patterns, not file names. A pattern, as normal, means a shell wildcard pattern. So, at minimum, *, [], and ] are special. Possibly { and } as well. The documentation also mentions you ...


6

The escape sequences ESC [ ... m are called ANSI Escape Sequences. top sends them to your terminal to make it format output in color, bold, inverted text and so on. You never see these characters when running top but you see the resulting format. You could think of it as looking at a webpage in a browser - you don't see the <html>... formatting the ...


5

I was able to do it with a backslash: 25 % grep \< xmospos.c #include <stdio.h> #include <stdlib.h> #include <getopt.h> #include <X11/Xlib.h> A quoted less-than, and a quoted, backslashed less than both gave goofy answers.


5

You're having problems with quoting because you're calling popen with a commandline, which is passed to the shell. Ruby's string parser is either eating the double quotes or eating the backslash. You can either call popen with an array of strings, which will bypass the shell, or you can write emacs foo\\ bar which will escape the backslash that you want ...


5

That error happens any time you try to use a string where a number was expected. For example $((input.txt)) will cause the same error to be printed. In your case, it turns out you were assigning to an array which uses a numeric index. jw013 rightly explains you need to do declare -A (uppercase A) for your example to work. The reason why: When ...


5

TTY framebuffer console has no way to have more than 8-16 colors without kernel hacking, see this quote: "Although the Linux frame-buffer supports 256 (or more) colors, the Linux console driver does not; therefore, console applications are still limited to 16 colors on the Linux console, frame-buffer or not." So you can have no more than 16 or 8 colors. ...



Only top voted, non community-wiki answers of a minimum length are eligible