Tag Info

Hot answers tagged

29

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 ...


20

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 ...


20

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 ...


18

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) ...


18

Those are sequences of characters sent by your terminal when you press a given key. Nothing to do with bash or readline per se, but you'll want to know what sequence of characters a given key or key combination sends if you want to configure readline to do something upon a given key press. When you press the A key, generally terminals send the a (0x61) ...


16

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 ...


16

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).


13

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) ...


13

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.


13

The ^D character (aka \04 or 0x4) is the default value for the eof special control character parameter of the terminal or pseudo-terminal driver in the kernel (more precisely of the tty line discipline attached to the serial or pseudo-tty device). That's the c_cc[VEOF] of the termios structure passed to the TCSETS/TCGETS ioctl one issues to the terminal ...


12

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 ...


12

You need to tell echo to honor escape sequences. echo -e "Hi\nabcd" >> ab.txt


12

Generally, you only have to escape one time to make special character considered literal. Sometime you have to do it twice, because your pattern is used by more than one program. Let disscuss your example: man gcc | grep \\. This command is interpreted by two programs, bash interpreter and grep. The first escape causes bash knows \ is literal, so the ...


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

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.


10

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 ...


10

^C aka Ctrl+C will abort what you're doing and get you back to a normal prompt.


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

\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 ...


9

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


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."


9

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).


9

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 ...


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

-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 ...


8

Terminal dependent positioning control can be done with tput. This includes basic high-lighting and cursor positioning. For example to move the cursor to line-10, column-1 you would use tput cup 10 1. See the tput manpages.


7

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 ...


7

If you take a look at the ANSI ASCII standard, the lower part of the character set (the first 32) are reserved "control characters" (sometimes referred to as "escape sequences"). These are things like the NUL character, Life Feed, Carriage Return, Tab, Bell, etc. The vast majority can be emulated by pressing the Ctrl key in combination with another key. The ...


7

Your keyboard is not connected to xterm. It's connected to your PC. A kernel driver knows how to decode the key press and release sent by the keyboard and make that available to applications via a generic API on special device file. An X server is such an application that uses that API. It translates those key presses and releases into X "KeyPress" and ...



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