Tag Info

Hot answers tagged

21

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


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


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


15

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

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


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


12

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.


11

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


11

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

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


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

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

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


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

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.


9

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


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

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

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

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


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.


8

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. That's the c_cc[VEOF] of the termios structure passed to the TCSETS/TCGETS ioctl one issues to the terminal device to affect the driver behaviour. The typical command that sends those ioctls is the ...


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

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

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

You can use the reset command, that will reset the terminal settings.


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



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