date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,328,417,304,000
I am trying to configure my bash ~/.inputrc to these settings (Note: ←, → mean the left and right arrow keys) Ctrl + ← - should jump back a word Ctrl + → - should jump forward a word Currently I have this in my ~/.inputrc and it doesn't work. Ctrl + arrow produces nothing. "\eC-5C":forward-word "\eC-5D":backward-wor...
Gnome-terminal (more properly VTE) imitates some version of xterm's escape sequences. How closely it does this, depends on the version of VTE. The relevant xterm documentation is in the PC-Style Function Keys section of XTerm Control Sequences. What you are looking for is a string like \e[1;5D (for control left-arrow...
What is the gnome-terminal ANSI escape sequence for "CTRL + arrow/s"?
1,328,417,304,000
Any idea what could be causing this? Without using grep, the only stuff display there are the ISO codes and empty space. Software used Command: ./trans --id --input /path/to/txt | grep ISO | grep [a-z] root@box /test # alias grep alias grep='grep --color=auto' root@box /test # type grep grep is aliased to `grep --col...
The screenshot appears to show mangled ANSI colour codes, which control text rendering. Bold/bright text is produced with the sequence ␛[1m, which is usually interpreted by your terminal and not displayed on the screen directly: it just makes the next bit of text bright. The screenshot of the ungrepped output shows th...
Weird symbols on screen when using grep?
1,328,417,304,000
I've got a script that scp's a file from remote host back to local. Sometimes the file names contain spaces. scp does not like spaces in its file names. For some reason my attempts at handling the spaces have not resulted in the correct scp path. Code: PATH=/var/root/Documents/MyFile OG-v1.2.3.pkg scp $PATH [email pro...
You should quote both the declaration and the usage path="/var/root/Documents/MyFile OG-v1.2.3.pkg" scp "$path" [email protected]:/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. (I've chan...
Trouble in script with spaces in filename
1,328,417,304,000
I have defined the color red using tput red=$(tput setaf 1) to colorize warnings in my program. This works fine: printf '%sfail\n' "$red" # prints 'fail' in red But on one occasion I would like to print out the escape sequence as-is, something like: \E[31mfail How would I do this? I know printf has a %q flag but it ...
Sounds like you want the opposite of printing them literally, you want those escape characters converted to a printable descriptive form like \E or \033, ^[... If it's just the ESC (0x1b) character you want to convert to \E, then with ksh93, zsh or bash (typically, the same ones that also support that non-standard %q)...
How to print control characters with escape sequences?
1,328,417,304,000
Is there a pastebin service that supports colors? I understand some of them have syntax hilighting, but I'd like to do arbitrary coloring, preferably using the terminal escape sequences. For example, I'd like to do: grep --color=force foo /etc/motd | pastebinit Does anyone know such a cool site?
Termbin.com supports what you need. $ grep --color=force foo /etc/motd | nc termbin.com 9999 http://termbin.com/xxxx $ curl http://termbin.com/xxxx You'll get exactly what you sent. The service is running on a free and open software called Fiche so you can also install your own.
is there a pastebin service that supports terminal escape sequences?
1,328,417,304,000
I have this Bash script for i in 1 2 3 do for j in 4 5 6 do echo "hello_$i_$j" done done but it prints hello_4 hello_5 hello_6 three times, whereas (you may guess) I want hello_1_4, hello_1_5, etc. Escaping only the underscore or only the dollar sign does not work. Any ideas? Thanks!
Add the line: set -u to the top of your code. Then rerun and see what you get. The error that variable i_ is unbound, meaning not defined anywhere. Now why is bash talking about this variable i_? You did not define it anywhere. Look closely at your echo statement: "hello_$i_$j" the underscore after the $i is being see...
Escaping _$ (underscore and dollar sign) [duplicate]
1,328,417,304,000
I'd like to use grep with a PCRE expression that contains the < character. Bash thinks I want to redirect, but I don't want to. How can I escape <?
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.
How to escape < or > in a parameter in shell?
1,328,417,304,000
On my Windows7 machine, I'm traversing to the installed path of PuTTy Application and running: plink <hostname> to connect to my remote Linux host. I see some unrecognized characters in the output as: -bash-3.2$ ls -lrt ←[00mtotal 96 drwx------ 5 lg262728 lg262728 4096 Jun 10 15:32 ←[00;34mmyScripts←[00m drwx------ ...
As michas has explained, those are terminal escape sequences. How they are interpreted is up to the terminal. You can do as michas has suggested and call ls like \ls, which will call the ls executable in $PATH, instead of the common shell alias ls --color=auto. To remove that shell alias you could do: unalias ls You ...
What is the problem with the output of plink?
1,328,417,304,000
Suppose for the sake of argument my password below is abc123@ I need to authenticate my linux machine through a corporate proxy to get patches and updates... normally I'd use this: export HTTP_PROXY='http://<Americas\Username>:<Password>@proxy.foo.com' export http_proxy='http://<Americas\Username>:<Password>@proxy.foo...
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).
export HTTP_PROXY and special characters in passwd
1,328,417,304,000
Recently, I have been playing around a lot with color in the terminal and, therefore, with escape sequences, too. I've read the relevant parts of the Bash manpage along with numerous helpful pages on the Net. I've got most of what I want working; a nice color Bash prompt, for example. That said, I am still somewhat ...
The "non-printing escape sequence" is needed when using non-printing characters in $PS1 because bash needs to know the position of the cursor so that the screen can be updated correctly when you edit the command line. Bash does that by counting the number of characters in the $PS1 prompt and then that's the column num...
Non-printing escape sequence: when?
1,328,417,304,000
I executed the following command # top > /home/user/top_output.txt Nothing Happened for a while and then i pressed Ctrl+C. When i checked the file that was created, it had the contents in it. So i fired cat command on it and it gave me this output. But when i tried the same thing with the less command i got th...
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 s...
Cat and Less give different output
1,328,417,304,000
Nano calls it ^L, but of course, typing something like $ grep -v "^\^L" file doesn't work. Its unicode codepoint is 000C. How can I match it in a regular expression?
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 gr...
How can I match the page break character in a regular expression?
1,328,417,304,000
I've been looking into escape sequences lately, and I'm surprised of what they can do. You can even move an xterm X11 window with them (try printf '\e[3;0;0t'), wow! The most common way to know what features a terminal supports seems to be using a database. That's what ncurses does, and it's used by 99.9% of applicati...
It's not as simple as you might suppose. xterm (like the DEC VTxxx terminals starting with VT100) has a number of reports for various features (refer to XTerm Control Sequences). The most generally useful is that which tells what type of terminal it is: CSI Ps c Send Device Attributes (Primary DA). Not all termina...
Terminal escape sequences: why don't terminals report what features they support, instead of relying on terminfo?
1,465,563,411,000
When I used shell in a box and when I call less command (echo foo | less) in ajax response there was this code: \u001B[?1049h\u001B[?1h\u001B=\rfoo\r\n\u001B[7m(END)\u001B[27m\u001B[K what does \u001B[?1049h and \u001B[?1h escape sequences do, also what is \u001B=? Are they documented somewhere?
\u001B is an unnecessarily verbose ASCII escape character, which seems to have been introduced for ECMAScript6. POSIX would use octal \033, and some others allow hexadecimal \01b. The upper/lower case of the number is irrelevant. The \u001B[?1049h (and \u001B[?1049l) are escape sequences which tell xterm to optional...
What does [?1049h and [?1h ANSI escape sequences do?
1,465,563,411,000
In bash, I press ctrl+v to start verbatim insert. In the verbatim mode, I press the Esc key and bash shows ^[. I redirect it to file esc. Also in the verbatim mode, I press ctrl key with [ key, and bash shows ^[. I redirect it to file ctrl. Next, I compare the two files, and they are the same! $ echo '^[' > esc $ ech...
This looks to follow the same logic as Ctrl-A, or ^A being character code 1, and ^@ being used to represent the NUL byte. Here, the ^ is a common way of representing Ctrl with another key. Namely, entering Ctrl-foo gives the character code of foo with bit 6 cleared, reducing the character code by 64. So, A is characte...
Why do `ctrl+[` and `ESC` both produce `^[`? [duplicate]
1,465,563,411,000
I'd like to print a man style usage message to describe a shell function like this output man find: NAME find - search for files in a directory hierarchy SYNOPSIS find [-H] [-L] [-P] [-D debugopts] [-Olevel] [starting-point...] [expression] DESCRIPTION This manual page documents the GNU versi...
The backtick introduces a command substitution. Since the here-document is not quoted, this will be interpreted by the shell. The shell complains since the command substitution has no ending backtick. To quote a here-document, use cat <<'END_HELP' something something help END_HELP or cat <<\END_HELP something someth...
Bad substitution: no closing "`" in a heredoc / EOF
1,465,563,411,000
I'm colorizing the header of a table formatted with column -ts $'\t' Works well without color codes, but when I add color codes to the first line column doesn't properly align the output. Without colored output it works as expected: printf "1\t2\t3\nasdasdasdasdasdasdasd\tqwe\tqweqwe\n" | column -ts $'\t' But when add...
I imagine that column doesn't know that \e[7m is a v100 escape sequence that takes no space in the output. It seems to asssume character codes 0 to 037 octal take no space. You can get what you want by putting the initial escape sequence on a line of its own, then removing that newline from the output: printf '\e[7m\n...
Issue with column command and color escape codes
1,465,563,411,000
My prompt string is printed using this statement, printf '\033]0;%s@%s:%s\007' user host /home/user Why does it need an escape character (\033) and a bell character (007)? When i ran the same command manually, it prints nothing. When i removed the escape characters and gave the command as, printf '%s@%s:%s' user hos...
Only \033 is an escape and it initiates the escape sequence up until and include the ;. \033]0;. This initiates a string that sets the title in the titlebar of the terminal and that string is terminated by the \007 special character. See man console_codes: It accepts ESC ] (OSC) for the setting of certain resources...
Bell and escape character in prompt string
1,465,563,411,000
So in bash, When I do echo \* * This seems right, as * is escaped and taken literally. But I can't understand that, when I do echo \\* \* I thought the first backslash escaped the second one thus two backslash "\\" will give me one "\" in literal. and * followed carrying its special meaning. I was expecting: ech...
If you don't have a file in the current directory whose name starts with a backslash, this is expected behaviour. Bash expands * to match any existing file names, but: If the pattern does not match any existing filenames or pathnames, the pattern string shall be left unchanged. Because there was no filename starting...
echo \\* - bash backslash escape behavior, is it evaluated backwards?
1,465,563,411,000
My understanding is that terminals often use ANSI control-codes to represent non-alphanumeric character sequences. For example, when editing .inputrc for Bash in Linux, it's easy to find code sequences that look as follows: "\e[A": history-search-backward "\e[B": history-search-forward "\e[C": forward-char "\e[D": bac...
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 u...
Reverse control-code look up for terminals
1,465,563,411,000
I always thought that bash treats backslashes the same when using without or with double quotes, but I was wrong: [user@linux ~]$ echo "foo \ " foo \ [user@linux ~]$ echo foo \ # Space after \ foo So I thought backslashes are always printed, when using double quotes, but: [user@linux ~]$ echo "foo \" " foo " [user@li...
Section 3.1.2.3 Double Quotes of the GNU Bash manual says: The backslash retains its special meaning only when followed by one of the following characters: ‘$’, ‘`’, ‘"’, ‘\’, or newline. Within double quotes, backslashes that are followed by one of these characters are removed. Backslashes preceding characters...
Why is a single backslash shown when using quotes
1,465,563,411,000
Is it possible to escape all meta characters of a string inside a variable before passing it to grep? I know similar question has been asked before on SE (here) and also a good explanation here, but I was just curious about whether it is possible with basic/extended posix regex pattern instead of perl pattern? (curre...
How to quote special characters (portably) The following snippet adds a backslash before each character that's special in extended regular expressions, using sed to replace any occurence of one of the characters ][()\.^$?*+ by a backslash followed by that character: raw_string='test[string]\.wibble' quoted_string=$(pr...
Escaping of meta characters in basic/extended posix regex strings in grep
1,465,563,411,000
So I'm writing a terminal emulation (I know, I should just compile putty, etc.) and am at the stage of plodding through vttest to make sure it's right. I'm basing it on the VT102 for now but will add later terminal features such as color when the basics are working right. The command set is mostly ANSI. DEC had their ...
I got in touch with Thomas Dickey (invisible-island.net) who maintains xterm and vttest - he explained that CSI 0 C is the same as CSI 1 C or CSI C in xterm. For anyone looking for more information on terminal programming I highly recommend checking out the xterm source he hosts - specifically the ctlseqs.txt inside x...
DEC ANSI command sequence questions; cursor movement
1,465,563,411,000
I am confused about how Ctrl-key combinations work in terminal. In bash man page, there are various combinations such as: C-e - go to end of the line C-f - go one character forward etc. But then there are some undocumented shortcuts such as: C-j (OR C-m) for return key. C-h for backspace C-i for tab etc. Are these...
The behavior of C-m, C-i, etc. is implemented by bash, but the fact that they're the same thing as Return, Tab, etc. is due to the behavior of the terminal. All terminals behave like this because all terminals have always behaved like this and it's what applications expect. The interface between a terminal and an appl...
Question about behavior of control key shortcuts
1,465,563,411,000
In my directory I have two files with space, foo bar and another file. I also have two files without space, file1 and file2. The following script works: for f in foo\ bar another\ file; do file "$f"; done This script also works: for f in 'foo bar' 'another file'; do file "$f"; done But the following script doesn't w...
For your command line parsing, arrange with the pathname operands to always be the last ones on the command line: ./myscript -a -b -c -- 'foo bar' 'another file' file[12] The parsing of the options would look something like a_opt=false b_opt=false c_opt=false while getopts abc opt; do case $opt in a) a_...
Bash for loop with string var containing spaces
1,465,563,411,000
I thought ls colors are defined as <file_type>=[<bg(40-47)>];<font_spec(0:5)>;<font_color(30-37)> but, I recently found this where there are more colors and colors are specified as, e.g.: .tar 00;38;5;61 for a 256-color terminal. What does this definition mean?
The argument to a LS_COLORS directive is a string that is written to the terminal as part of an escape sequence. When displaying a file name, ls writes \e[, then the string associated with the file type, then m, then the file name, then \e[0m (where \e represents an escape character). This is the escape sequence that ...
LS_COLORS for 256-color terminal
1,465,563,411,000
I have input coming from pipe which contains special escape characters. For illustration, the stream looks like this: printf "foo.bar\033[00m" > file cat file How can I remove the trailing .bar\033[00m? I have tried the following, but that does not work: cat file | sed 's/\.bar\033[00m//'
If your file contains control characters such as printf "foo.bar\033[00m" > file then to remove the specific, single occurrence of .bar\033[00m write the following: sed $'s/\.bar\033\[00m//' To remove all kinds of escape sequences in the entire file: sed $'s/\033\[[0-9;]*m//g' The dollar-before-single-quoted-string...
Remove escape characters using sed
1,465,563,411,000
ESC sends \x1b. That's 1 byte: the actual escape character. Page Up sends \x1b[H. That's 3 bytes. F2 sends \x1b[OQ. That's 4 bytes. F5 sends \x1b[15~. That's 5 bytes. What's the maximum length for one of these? Is this documented somewhere?
There is no predefined limit for the length of control sequences. OP gives as examples some strings sent by special keys, which are documented in XTerm Control Sequences. xterm starts with a list of possible key codes, may add codes for modifiers as outlined in the Alt and Meta keys section. There is no table of len...
What's the maximum length for a multibyte escape sequence?
1,465,563,411,000
I am writing a script which executes a number of programs with arguments. To simplify it as much as possible, consider the following example: programs=( "ls" "echo" ) declare -A parameters parameters["ls"]="-l /tmp/foo" parameters["echo"]="Hello" for program in "${programs[@]}" do $program ${parameters[$program]} d...
First, create an array with the parameters. Then, store the array string value (found with declare -p) at parameters, and recover and use it as an actual array later on like in: #!/bin/bash programs=( "ls" "echo" ) declare -A parameters arrayTmp=("-l" "/tmp/foo bar") parameters["ls"]="`declare -p arrayTmp |sed -r "s...
Escaping strings in associative arrays (bash)
1,465,563,411,000
I have been trying to: cp file.csv file.$(date +%D).csv But it fails because the filenames is: file.03/27/19.csv with the slash of separate directories. And I have been trying again to: cp file.csv file.$(printf "%q" $(date +%D)).csv But it still fails.
You can't have / (byte 0x2F on ASCII-based systems) in a file name, period. You can use characters that look like / like ∕ (U+2215 division slash) or ⁄ (U+2044 fraction slash though found in fewer of the charsets used in current locales), so you could do (provided that U+2215 character exists in the locale's charset, ...
Escape a mm/dd/YY backup date in a file name
1,465,563,411,000
I have one-line that I want to call using alias. while printf '%s ' "$(df -P / | awk 'NR==2 { print $(NF-1) }')"; do sleep 30; done I tried to escape ' like \' but it didn't work. What is the correct syntax to use above one-liner in alias?
alias my_du=$'while printf \'%s \' "$(df -P / | awk \'NR==2 { print $(NF-1) }\')"; do sleep 3; done' You can check the result with alias my_du If $() is quoted by " instead of ' or \ then it is substituted and the result rather than the intended program call becomes part of the alias definition.
How to use ' in alias?
1,465,563,411,000
In sh (not Bash), how would we abort execution of command when the prompt is in > mode? For example, when entering a string with quotes only at the beginning, it makes the prompt look like >, without the ability to quit it normally, unless hitting Ctrl + D. Example: root@MyPC:~# echo "hello > I am > (How do I exit of ...
^C aka Ctrl+C will abort what you're doing and get you back to a normal prompt.
Exit of "> " mode in Unix shell
1,465,563,411,000
Let's say we have a generic keyboard with some unknown keys which may send escape sequences to terminal. The keyboard is connected to an xterm terminal emulator running on a generic BSD/Linux. To create correct mapping for the unknown keys, we must first know what escape sequences they send to the xterm. But how to kn...
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 presse...
How to find out the escape sequence my keyboards sends to terminal?
1,465,563,411,000
How can a command-line argument containing a dot (.) be passed? Are there any escape sequences for capturing characters like dot? The following invocation of a bash-script from the shell does not work: # ./deploy.sh input.txt ./deploy.sh: line 9: input.txt: syntax error in expression (error token is ".txt") I have tr...
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, associati...
Passing a bash command-line argument containing a dot
1,465,563,411,000
I am trying to write a program that runs a console program like gcc and displays its output in color. I used openpty instead of pipe to pretend to be a character device and now get ANSI escape codes that carry color information. I tried some programs and they sometimes give me the code CSI [ 49 m. Both wikipedia and t...
\61 is the octal code for the 1 character in ASCII, so \e[\61m or \33[\61m or \33\133\61\155 or \33[1m is <ESC>[1m. That's CSI 1 m. See Wikipedia or the xterm documentation. $ printf '\e[\61m' | od -An -vto1 -tc 033 133 061 155 033 [ 1 m $ tput bold | od -An -vto1 -tc 033 133 061 155 033 [ 1 m For the...
Where is the character escape sequence `\033[\061m` documented to mean bold?
1,465,563,411,000
The methods I found break things further down the line by also affecting linebreaks. For example... $ message="First Line\nSecond Line"; $ echo "${message^^}" FIRST LINE\NSECOND LINE Is there an elegant way to convert a string to uppercase, but leaving escaped characters alone, to get the following output instead? F...
echo "$message" | sed -e 's/^[[:lower:]]/\u&/' -e 's/\([^\]\)\([[:lower:]]\)/\1\u\2/g' \ -e 's/\([^\]\)\([[:lower:]]\)/\1\u\2/g' -e 's/^[[:lower:]]/\u&/'  If the first character in the string (or, more generally, the first character on a line) is a lower-case letter...
Convert to uppercase, except for escaped characters
1,465,563,411,000
I have a pattern variable with below value: \"something//\\anotherthing' and a file with below contents: \"something//\\anotherthing' \"something//\\anotherthing \"something/\anotherthing' \"something\anotherthing' \\"something\/\/\\\\anotherthing' When I compare a line read from the file against the pattern in the ...
The ~ operator does pattern matching, treating the right hand operand as an (extended) regular expression, and the left hand one as a string. POSIX says: A regular expression can be matched against a specific field or string by using one of the two regular expression matching operators, '~' and "!~". These operat...
Where are escape sequences needed when using tilde ~ operator in awk?
1,465,563,411,000
This works (puts the date and time in the clipboard) in just iTerm: printf "\e]1337;Copy=:$(date | base64)\a"; echo $(pbpaste) This works in tmux running locally (using the DCS passthrough): printf "\ePtmux;\e\e]1337;Copy=:$(date | base64)\a\e\\"; echo $(pbpaste) This works in tmux running remotely: printf "\ePtmux;\e...
You need to double every \e for each tmux, including the \e in the terminating \e\\, so: printf "\ePtmux;\e\ePtmux;\e\e]1337;Copy=:$(date | base64)\a\e\e\\\e\\" Alternatively if you configure tmux to use OSC 52 and then turn it on in iTerm2 ("Applications in terminal may access clipboard" from a quick search) it will...
How can I send an escape sequence from a nested tmux session to iTerm2?
1,465,563,411,000
When you run cal on Linux, the output for the current month will reverse video highlight the current day. When I send that output to hexdump -c, I get some interesting results: 0000000 N o v e m b e r 2 0 1 6 0000010 \n S u M o T u ...
Ctrl-H is backspace, it moves the cursor one step to the left. Sending an underscore, a backspace, and some other character was the way to underline something on a hard-copy ("paper") terminal back in the good old days. This was used to highlight the current day in the output of cal. My cal program, when run in konsol...
Why does 'cal' use weird 08 / ^H / \b terminal code for highlighting and how does that work?
1,465,563,411,000
I am working with control sequences for text formatting and have stumbled upon some unexpected behavior. I have some text to output, in the middle of this text there is some smaller text block highlighted with a colored background. The original text may be pretty long, it may take a few lines, so the colored text bloc...
This has nothing to do with bash, it is purely an effect of the terminal's behavior, specifically scroll. When you reach the bottom of the screen, and start to type on the next line, the terminal creates a new blank line by pushing everything up one line. (In older terminals this destroys the top line. In newer termin...
Background color whitespace when end of the terminal reached
1,465,563,411,000
My coworker has the following in the ~/.bash_profile of many of our servers: echo -e "\033]50;SetProfile=Production\a" The text doesn't seem to matter, since this also works: echo -e "\033]50;ANY_TEXT\a" But no text doesn't work; the \a is also required. This causes his terminal in OSX to change profiles (different ...
Looking at the list of xterm escape codes reveals that (esc)]50;name(bel) sets the xterm's font to the font name, or to an entry in the font menu if the first character of name is a #. The simplest way to reset it is to use the xterm's font menu (Ctrl + right mouse click) and select an entry other than Default. Altern...
Escape code 50 in xterm
1,465,563,411,000
I know that Konsole supports an escape code like "\<Esc>]50;CursorShape=0\x7" that will change the cursor shape. I was wondering if any other terminal emulators support changing the cursor shape via an escape code?
The Linux VGA/framebuffer consoles use the Esc[?...c code. xterm supports the VT520 sequence DECSCUSR Esc[... q since patch 282.
Escape Code to Change Cursor Shape
1,465,563,411,000
On RHEL6 and CentOS 6, /etc/bashrc sets PROMPT_COMMAND here: case $TERM in xterm*) if [ -e /etc/sysconfig/bash-prompt-xterm ]; then PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm else PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"' fi ;; scre...
\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...
In Bash, why is PROMPT_COMMAND set to something invisible?
1,465,563,411,000
user prompt: user - / : up/down keys to locate historical commands. user - / : historical command clear the "historical command" : user - / :hist No matter how many times I hit BackSpace.. unable to delete "hist" part. technically it is not even there. but on the screen it simply wont clear out until I hit "enter...
Your final ANSII escape sequence isn't finished. The reset code (\e[0m), like the others, needs a [. Change your PS1 to: PS1="\[\033[38;5;190m\]\u - \W : \[\e[0m" Or, to keep things consistent: PS1="\[\033[38;5;190m\]\u - \W : \[\033[0m"
bashrc PS1 : user prompt won't clear entire text [duplicate]
1,465,563,411,000
$ ag findVersions( src/java/com/google -bash: syntax error near unexpected token `(' I tried quoting it, escaping it, both were not suitable. $ ag findVersions\( src/java/com/google ERR: pcre_compile failed at position 13. Error: missing ) $ ack findVersions\( src/java/com/twitter Invalid regex 'findVersions(': ...
Since the first argument is a regex, you'll have to both: escape regex special characters, and protect it from the shell ag 'findVersions\(' src/java/com/google
How use '(' token when using it for searching with ag / awk?
1,465,563,411,000
Compare the following two commands: mysqldump database_name --hex-blob -uuser_name -p | tee database_name_tee.sql mysqldump database_name --hex-blob -uuser_name -p > database_name_out.sql If I run the first, on completion I see the following on my terminal: $ 62;c62;c62;c62;c Where does this come from? Does it sugge...
There are no escape characters in the octal dump (those would be 033). There are a few 8-bit control codes (generally not implemented by most terminals other than xterm). The octal 232 is hex 0x9a, and (referring to XTerm Control Sequences): ESC Z Return Terminal ID (DECID is 0x9a). Obsolete form of CSI c (DA)...
What does it mean when characters appear on the prompt after an operation?
1,465,563,411,000
I found that by printing \r from a script the cursor moves to the beginning of the line. What character will move the cursor up one line? Where is a list of these special characters? EDIT: Working in OSX. Also, \a rings the bell.
If your terminal emulator supports ANSI escape sequences, you can move the cursor up by running this: echo -n -e '\033[2A' or ruby -e 'print "\033[2A"' This will move the cursor up 2 lines. It works in gnome-terminal and xterm and many others.
What are the special characters to print from a script to move the cursor?
1,465,563,411,000
I understand that any character is comprised of one or more byte/s. If I am not mistaken, at least in *nix operating systems, a character will generally (or totally?) be comprised of only one byte. What is the difference between a byte and a character (at least *nixwise)?
A byte is by convention and POSIX definition eight bits. A bit is a binary digit (i. e. the fundamental 1 or 0 that is at the base of nearly all digital computing). A character is often one byte and in some contexts (e. g. ASCII) can be defined to be one byte in length. However, Unicode and UTF-8 and UTF-16 define e...
What is the difference between a byte and a character (at least *nixwise)?
1,465,563,411,000
I'm running iwlist wlo1 scan | grep ESSID inside a script. It displays French characters in the following format \xC3\x89 for É and \xC3\xA9 for é. I'm not sure what this format is called. I tried using an answer for converting unicode echo -ne '\xC3\xA9' | iconv -f utf-16be but it converted to 쎩. What is the officia...
Hexdecimal numeric constants are usually represented with 0x prefix.Character and string constants may express character codes in hexadecimal with the prefix \x followed by two hex digits. echo -ne '\xC3\x89' should give you É. -e - enable interpretation of backslash escapes(including \xHH - byte with hexadecimal val...
Bash convert \xC3\x89 to É?
1,465,563,411,000
This works fine: sed -i 's# @driver.find_element(:xpath, "//a\[contains(@href,##' temp_spec.rb against a source of @driver.find_element(:xpath, "//a[contains(@href,'change_district')]").click I am just left with: 'change_district')]").click` but when I try to add a single quote at the end it fails: sed -i 's# ...
The strings inside single quotes are used verbatim by the shell (and hence cannot contain other single quote, since that would be treated as the closing one of a pair). That said, you have several options: end the single-quoted string, add escaped (either by backslash or double quotes) single quote, and immediately s...
How to escape a single quote? [duplicate]
1,465,563,411,000
I have found this answer providing how to manipulate the current xterm window's dimensions, ie: echo -ne "\e[8;30;30t" How can I modify this to maximize the window (xterm's alt + enter shortcut)? Also, where do I find more info on these xterm command line modifiers? UPDATE: See multiple solutions below for both maxim...
The commands are echo -ne '\e[9;1t' to maximize and echo -ne '\e[9;0t' to restore the original size. It's described in the xterm control sequences documentation.
Maximize xterm via bash script
1,479,710,941,000
I've checked out a lot of links on how to grep individual escape characters or literal strings, but I just cannot get them to combine to find the background-red ANSI escape sequence ^[41m, even typing the ^[ as both Ctrl+V+Ctrl+[ and the two literal characters ^+[ and using both the -E and -F flags. The raw bytes I am...
but I just cannot get them to combine to find the background-red ANSI escape sequence ^[41m If you use vim to open this file, you will know it's not ^[41m, instead it's ^[[41m, which ^[ navigate by arrow key as a set: 1b is Escape represent by single escape character ^[ which can be invoked by Ctrl+V follow by Es...
grep for an ANSI escape code
1,479,710,941,000
I am trying to make a script that takes some atom feeds and posts them to slack through the Slack API via curl. What I have now works for simple texts, but some of them have double quotes or & characters in them and that seems to annoy slack API as I get an invalid payload error. Here's my script: #!/bin/bash rsstail ...
You need to url-encode the data, and the easiest way to do this is to get curl to do it for by replacing the -d option by --data-urlencode. Also, you need to use double quotes or the shell will not expand the variable, so we have curl \ -H "Accept: application/json" \ -X POST \ --data-urlencode "${payload...
Escape strings to be posted via curl
1,479,710,941,000
My username is user1 and password is mypass8@ I wish to pass this username and password to curl command. How do i escape the @ in the password when passing it to curl command ? curl -k -X POST https://user1:mypass8@@myshop.com/job/build I get the error message: MESSAGE:Invalid password/token for user: user1 I also ...
I fixed the issue using a base64 conversion... echo -n '[USERNAME]:[PASSWORD]' | base64 This will generate a token to pass to curl as a header in this way: curl -H 'Authorization: Basic [add value obtained from the previous cmd]'
How to escape '@' in curl command password field
1,479,710,941,000
I am playing around with shell scripts that use ANSI codes and found that for one reason or another different escape codes are supported depending on your terminal/OS. In some cases I get a dump of unparsed gunk unexpectedly, which I'm assuming means my terminal (on Mac OS) doesn't support that escape code used, despi...
Have you got specific operations in mind? Here is an example of using standout mode, which on many terminals will give a strong visible result: tput smso; echo hello, world; tput rmso The tput tool uses the value of the $TERM environment variable to determine which escape sequences to output - if any. For example TER...
Programmatically detect the ANSI escape code supported by terminal
1,479,710,941,000
Help me to decipher the escape sequences created by ncurses library and catched by strace. I am exploring how ncurses interacts with terminal and want to understand its "handshake protocol". I have found some descriptions already, but didn't understand all of them though, like "Set cursor key to cursor". echo $TERM pr...
For XTerm and anything that claims compatibility with it, you'll want this: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html You'll also need the manual for the VT100 terminal, which XTerm emulates and expands on: https://vt100.net/docs/vt100-ug/contents.html The Linux console_codes(4) man page describes the co...
The deciphering of ncurses escape sequences
1,479,710,941,000
I'm trying to match against some UTF-8 characters. The problem is grep doesn't translate \x byte escapes, so this fails: echo -e '\xd8\xaa' | grep -P '\xd8\xaa' while this succeeds: echo -e '\xd8\xaa' | grep -P $(printf '\xd8\xaa') Can grep understand byte escapes directly without using printf? How?
This fails: $ echo -e '\xd8\xaa' | grep -P '\xd8\xaa' | hexdump This succeeds: $ echo -e '\xd8\xaa' | grep -P $'\xd8\xaa' | hexdump 0000000 aad8 000a 0000003 Documentation From man bash: Words of the form $'string' are treated specially. The word expands to string, with backslash-esca...
Making grep understand byte escapes
1,479,710,941,000
I'm reading a book on shell programming and learning that following commands are equivalent, which beep on my Mac but don't make any sound on Ubuntu: $ echo $'\a' $ echo -e "\a" $ however in both cases, terminal prompts a blank line. My questions are: What's $'\a' here? Parameter expansion, command substitution or...
don't make any sound on Ubuntu: perhaps because your particular terminal emulator is configured to avoid sounds, or because the pcspkr kernel module is unloaded, etc... You could use another terminal emulator (e.g. the old xterm) which should beep. What's $'\a' here? Read the chapter on shell expansion of the Bas...
Mechanism of BELL character '\a'?
1,479,710,941,000
As others have pointed out, color codes in PS1 should be bracketed by \[ and \] to avoid them taking up horizontal space. I've added the necessary code to .bashrc: highlight() { if [ -x /usr/bin/tput ] then printf '\[' tput bold printf '\]' printf '\[' tput setaf $1 ...
It seems that any escape sequence actually in PS1 literally needs to be wrapped in \[ and \], but if you call a function or command that produces output, it does not need to be wrapped. So why not just move the "\$(exit_code=\${?#0} highlight_error \"\${exit_code}\${exit_code:+ }\")" stuff inside a function, e.g. pr...
Re-escape brackets in PS1
1,479,710,941,000
am using iTerm with Tmux, but I see this without tmux. If I hit SHIFT+SPACE I get the escape sequence ^[[32;2u. Is there a way to suppress it or disable that escape sequence? I am not seeing it in my preferences as a predefined escape sequence
The solution depends on the application that enables the xterm modifyOtherKeys feature. iTerm2 recently adapted/imitated/whatever this from xterm. The xterm manual in turn mentions a page in the FAQ XTerm – “Other” Modified Keys which gives information on the feature, and in that page's Other Programs section points t...
SHIFT+SPACE on terminal sends escape sequence
1,479,710,941,000
I am attempting to write a simple bash parser. I am following the steps in this wiki. One of the assumptions I make is that I can do a pass over the entire input string and remove all single and double quotes if I escape the characters correctly. When run in the bash, they two strings should yield the same output. Thi...
This is Word Splitting in action. Before we start, peruse the Shell Expansions paying attention to the order in which they are performed. Looking at node -p "console.log($(echo \"hello world\"))" brace expansion? no tilde expansion? no parameter expansion? none here command substitution? yes, leaving you with no...
Escaping double quotes inside command substitution
1,479,710,941,000
I'm having a problem with a script. It is meant to change a value in a file called %DIR% so that it becomes a path name. The problem is the slashes in the directory name upset sed, so I get weird errors. I need to convert the slashes in the path name into escaped slashes. So /var/www would become \/var\/www But I don...
Since you say you are using Bash, you can use Parameter Expansion to insert the slashes: $ directory=/var/www $ echo "${directory//\//\\/}" \/var\/www This breaks up as substitute directory replacing every (//) slash (\/) with (/) backslash+slash (\\/). Putting this into your sed command gives: sed -i "s/%DIR%/${di...
Bash converting path names for sed so they escape [duplicate]
1,479,710,941,000
I'm having trouble understanding what I need to escape when using sh -c. Let's say I want to run the for loop for i in {1..4}; do echo $i; done. By itself, this works fine. If I pass it to eval, I need to escape the $: eval "for i in {1..4}; do echo \$i; done", but I cannot make it work for sh -c "[...]": $ sh -c "for...
The usual wisdom is to define the script (after the -c) inside single quotes. The other part you need to use is a shell where the {1..4} construct is valid: $ bash -c 'for i in {1..4}; do echo $i; done' # also work with ksh and zsh One alternative to get it working with dash (your sh) is to make the expansion on the...
How to run a loop inside sh -c
1,479,710,941,000
I have a json string inside json. This got encoded multiple times and I ended up with many escape backlashes: \\\". The much shortened string looks like, '[{"testId" : "12345", "message": "\\\"the status is pass\\\" comment \\\\\"this is some weird encoding\\\\\""}]' I am trying to grep and get the number of occurren...
To look for \\\" anywhere on a line: grep -F '\\\"' That is, use -F for a fixed string search as opposed to a regular expression match (where backslash is special). And use strong quotes ('...') inside which backslash is not special. Without -F, you'd need to double the backslashes: grep '\\\\\\"' Or use: grep '\\\{...
Match pattern \\\" using grep
1,479,710,941,000
I want to cat all files to one new file in a bash script. For example there are three files in my dir: - file_a.txt - file b.txt - file(c).txt When I write the following, it works without problems: cat "file"*".txt" >> out_file.bak No I want to make it more flexible/clean by using a variable: input_files="file"*".txt...
It depends when you want to do the expansion: When you define the variable: $ files=$(echo a*) $ echo $files a1 a2 a3 $ echo "$files" a1 a2 a3 When you access the variable: $ files=a* $ echo "$files" a* $ echo $files a1 a2 a3
Use asterisk in variables
1,479,710,941,000
I wanted to find out what my terminal is sending for Ctrl+Backspace and Alt+Backspace, the standard way to do this is to run cat on the terminal and typing stuff usually works, but with certain output like these, the results are tricky. I am guessing that Alt+Backspace is sending \x1b\x7f (that is, escape backspace) b...
Simply use this command: showkey -a
How can I find out what the escape codes my terminal are sending for certain special ones that cat will not show?
1,479,710,941,000
I am processing a huge stream of CSV data coming from a source which includes special characters, such as the following: `÷ Þ Ÿ ³ Ù ÷` Here is an example row from a data set which includes these characters: '÷ÞW' , 'ŸŸŸŸŸŸŸ', '³ŸŸÙ÷' Here is another example taken from a different data set: WCP16,2013-06-04 20:06:24,...
I'm not sure exactly what you mean by "special characters", so I'm going to assume that you want to get rid of non-ASCII characters. There are a few different tools that might work for you. The first few that come to mind for me are: iconv (internationalization conversion) tr (translate) sed (stream editor) iconv (i...
Remove all type of special characters in unix .csv file
1,479,710,941,000
If I do git status --short, git lists files that are not tracked with two red question marks in front: I'm trying to store this in a variable and print it with color later. Here's my bash script: #!/bin/bash status=$(git status --short) echo -e "$status" I thought the -e flag would cause bash to color the output, bu...
Most programs that produce color will, by default, only produce it when the output is to a terminal, not a pipe or file. Generally, this is a good thing. Often, however, there is an override switch. For example, for ls, one can use --color=always and, as a result, color can be saved in shell variables. For example...
How do I store colored text in a variable and print it with color later?
1,479,710,941,000
I have this: I read down arrow key abc@abc-ubuntu:~/bashpratice$ read -n 3 key ^[[Babc@abc-ubuntu:~/bashpratice$ I am able to grep for it abc@abc-ubuntu:~/bashpratice$ echo $key | grep '\[' [B abc@abc-ubuntu:~/bashpratice$ echo $key | grep '\[B' [B But echoing the key just prints spaces abc@abc-ubuntu:~/bashpratice...
What happens when downarrow is typed in a terminal As reported by xxd -p, when typing ↓ + return : xxd -p ^[[B 1b5b420a The downarrow key leads to a sequence of 3 characters: the first is \x1b (a.k.a. escape, see man ascii), echoed on the terminal as ^[, second is \x5b, that is [, third is \x42, that is B. The last...
Trying to print up down arrow keys
1,479,710,941,000
When I do a search bindkey in the zsh plugins directory for key conflicts I get responses from both the .zsh script files and .md files, and some of the zsh readme files use a double quote in the bindkey statement. How would I do a search for bindkeys using both ' and " for quoting? For instance if search for usage of...
Of course, you need to escape the ^ character: grep -r 'bindkey "\^r' dir Then, you could use the "Extended Regex" Alternate character '|': grep -E 'bindkey "\^r''|'"bindkey '\^r" dir Which could be reduced to: grep -E 'bindkey ("|'"')"'\^r' dir [1] Or, if using bash, ksh or zsh, use the $' quoting (both ' and " co...
How can search for both single quotes and double quotes in a grep search?
1,479,710,941,000
Errata: Similar questions about this have been asked but after searching this for a few days there appears to be no answer to this specific scenario. Description of the problem: The second line in in the following bash script triggers the error: #!/bin/bash sessionuser=$( ps -o user= -p $$ | awk '{print $1}' ) print $...
It's the third line (print $sessionuser) that causes that error, not the second. print is a builtin command to output text in ksh and zsh, but not bash. In bash, you need to use printf or echo instead. Also note that in bash (contrary to zsh, but like ksh), you need to quote your variables. So zsh's: print $sessionuse...
Saving command output to a variable in bash results in "Unescaped left brace in regex is deprecated"
1,479,710,941,000
I am trying to print a sorted list of all zsh options, with set options colored green and unset options colored red. I cannot get sort to work properly with on the colored lines though.The below prints all the red options followed by all the green options: print -lP "%F{green}"${^$(setopt)} "%F{red}"${^$(unsetopt)} | ...
-k option of sort takes two numerical arguments: field and character. You want to sort on 6th character of first field. It is 6th character because %F{green} is replaced by ESC[32m. So this should work: print -lP "%F{green}"${^$(setopt)} "%F{red}"${^$(unsetopt)} | sort -k 1.6
Sorting strings with ANSI escape codes
1,479,710,941,000
I don't use bash often but I recall in the past to pass a tab or newline on the command line I would have to escape the character using the special $ character before a single quoted string. Like $'\t', $'\n', etc. I had read about quotes and escaping in the bash manual. What I want to know is when it's appropriate to...
You use $'...' when you want escape sequences to be interpreted by the shell. $ echo 'a\nb' a\nb $ echo $'a\nb' a b In perl, -e option get a string. If you use $'...', the escape sequences in string are interpreted before passing to perl. In your case, \r had gone and never passed to perl. With $'...': $ perl -MO=De...
When to use bash ANSI C style escape, e.g. $'\n'
1,479,710,941,000
It is bound to menu-complete in GNU readline. $ bind -p|grep menu "\e[Z": menu-complete # menu-complete-backward (not bound) # old-menu-complete (not bound) I think it's Meta-something.
Look in the terminfo database for your terminal for the key that sends this escape sequence. The infocmp command dumps the terminfo entry for the current terminal. $ infocmp | grep -oE ' k[[:alpha:]]+=\\E\[Z,' kcbt=\E[Z, The terminfo man page explains what cbt is the abbreviation of. (It also gives an example which ...
How do I generate the sequence "\e[Z" in a terminal?
1,479,710,941,000
So here's my deal: working in BASH, I have already built out a function which works just fine that accepts an array or any number of parameters, and spits out an interactive menu, navigable by arrows up or down, and concluding with the user hitting enter, having highlighted the menu item they desire (the output of whi...
You can read for -n 1, and read the following two if the first one is \033 and react accordingly. Otherwise, handle the number directly. #!/bin/bash read -n1 c case "$c" in (1) echo One. ;; (2) echo Two. ;; ($'\033') read -t.001 -n2 r case "$r" in ('[A') echo Up. ;; ...
BASH question: using read, can I capture a single char OR arrow key (on keyup)
1,479,710,941,000
Apologize if you feel this question very basic. Anyways, I am typing sed '/[iI]t/ a\\ Found it!' data but it says the error event not found. I tried escaping that ! with backslash \! but it doesn't work. I don't understand when backslash \ can escape a character and use it literally then why doesn't it work in s...
Which OS did you try it on? On HP-UX 8.11 csh there are 2 ways to cancel the speacial meaning of exclamation mark for history substitutions (see History substitutions in man csh). Put space after ! (couple of other characters work too) sed '/[iI]t/ a\\ Found it! ' data Escape it via \! sed '/[iI]t/ a\\ Found it\!' d...
How to use ! in the sed command?
1,479,710,941,000
From a pattern such as [string 1]{string 2} I want to extract string 2, the string between the last pair of matching curly braces -- that is delete [string 1] and the open { and close }. My attempt below breaks when there is a additional [, ] pairs in either string 1 or string 2. Desired Output: The desired output f...
Regarding to above input examples the script can be: sed s/[^\"\']*[^0-9]\]{\(.*\)}/\1/ <<\END "[]{foo bar 1}" "[abc]{foo bar 2}" "[]{foo[3]{xyz} bar 3}" "[]{foo $sq[3]{xyz}$ bar 4}" "[goo{w}]{foo $sq[3]{xyz}$ bar 5}" "[goo[3]{w}]{foo $sq[3]{xyz}$ bar 6}" "[goo[3]{w} hoo[3]{5}]{foo $sq[3]{xyz}$ bar 7}" END produces "...
sed to match pattern between matching curly braces
1,479,710,941,000
I have a log file and I'm looking to sort according to response time, 4th field: GET /api/user/john 200 0.194 ms - 7307 But it contains color tags, here's the output from vi: ^[[0mGET /api/user/john ^[[32m200 ^[[0m0.194 ms - 7307^[[0m Is there a simple way to do this?
Extract the field you want to sort on (typically with cut, sed or awk), and strip off its formatting escape sequences. You can find scripts for the second part in Removing control chars (including console codes / colours) from script output. I'll use uncolor below to stand for one of these scripts. Collate the result...
How to sort a column that also has color data?
1,479,710,941,000
This script outputs 5 lines with the third one being underlined: #!/usr/bin/env bash set -eu bold=$(tput bold) reset=$(tput sgr0) underline=$(tput smul) echo 'line 1 line 2 line 3 line 4 line 5' | awk -v bold="$bold" -v reset="$reset" -v underline="$underline" ' NR == 3 {print underline $0 reset} NR != 3 {prin...
less sends its own "reset" at the end of the line, which happens to be derived from the terminfo sgr0 by (ncurses) eliminating the ^O (reset alternate character set) because less is using the termcap interface. The termcap capability me which corresponds to terminfo sgr0 conventionally doesn't modify the alternate ch...
Why do I not need to reset text attributes with less?
1,479,710,941,000
I'm connected to Ubuntu server that is a member of a corporate Active Directory domain via likewise-open. The users are in the form mydomain\myuser. I can connect to it via ssh, escaping the \ with another \: ssh mydomain\\myuser@myserver I've generated a pair of keys via ssh-keygen, then tried to copy it to the remo...
The reason this is happening is because you are escaping it for the shell, but ssh-copy-id is also attempting to interpret it. This should work: ssh-copy-id 'mydomain\\myuser@myserver'
how to escape "\"in ssh-copy-id?
1,479,710,941,000
I know I can move the cursor with the escape codes, and I can also print at the cursor. What I'd like to know is if it is possible to pull the character under the cursor. I tried searching for such a code, but failed. So I assume it is not possible, but I'd like to ask if there is some way I failed to find.
This is not possible unless you modify your terminal emulator to make it possible; use curses library or equivalent.
Is it possible to get a character at terminal cursor using ANSI escape codes?
1,479,710,941,000
According to Bash tips: Colors and formatting (ANSI/VT100 Control sequences) I attemped to active blink code in my program, But may be blink code has been eliminated. Is it true? If is not true, Please help me to use blink code.
The blink feature depends upon the terminal (or terminal emulator). Most terminals you will use accept the control sequences documented in ECMA-48, e.g., VT100-compatible. The control sequence may cause blinking on a given terminal, or show as a particular color, or simply ignored by a given terminal Applications ...
blink code(escape code) has been removed?
1,479,710,941,000
I am not able to take care of special characters. I have the following perl script. while(@mapping_array[$i]) { chomp(@mapping_array[$i]); my @core= split ( / / , $mapping_array[$i]) ; @core[0] =~ tr/ //ds ; ## Deleting blank spaces @core[1] =~ tr/ //ds ; system("perl -pi -e 's/@core[0]/@core[1]/' ...
Sounds like you're looking for quotemeta. As explained in perldoc -f quotemeta: quotemeta EXPR Returns the value of EXPR with all the ASCII non-"word" characters backslashed. (That is, all ASCII characters not matching "/[A-Za-z_0-9]/" will be preceded by a backslash in the returned str...
Executing a 'perl command' from shell and executing the same command from perl script using system command
1,479,710,941,000
I was running a pipe command with one section being the following: sort -t $'\t' -T . -k1,1g When I was monitoring htop I saw this instead: What is the reason behind this? Does this mean my command is wrong or is there something wrong with htop?
There’s nothing wrong with your command, htop replaces control characters with question marks: (((unsigned char)data_c[j]) >= 32 ? ((unsigned char)data_c[j]) : '?') (characters with values less than 32 are control characters).
Why does `htop` display `$'\t'` as `?` in `sort` command?
1,479,710,941,000
I'm using the following script, but getting unexpected output. perl -pi -e '/DB_CHARSET/ and $_.="define('SOMETHING'/, true);\n"' file.txt This command adds define(SOMETHING, true); Since the text starts with ' then have " inside, how do I escape 'SOMETHING so that I end up with define('SOMETHING', true)? I've tried ...
You could use e.g. \x27 in the Perl string (the character code for ' in hex): $ perl -e 'print "foo\x27bar"' -l foo'bar or handle the quoting in the shell so as to give Perl a raw ': $ perl -e 'print "foo'\''bar"' -l foo'bar (First ' ends the quoted string, \' inserts the quote, the third ' starts a new quoted strin...
How to escape ' inside " in perl?
1,479,710,941,000
I need to understand this code snippet that I found in .profile file echo -en "\e[32;44m $(hostname) \e[m";echo -e "\e[m"
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 ne...
Unix Shell and colours
1,448,891,626,000
I have the following in my .bashrc file I use for a log: function log(){ RED="\e[0;31m" RESET="\e[0m" echo -e "${RED}$(date)" "${RESET}$*" >> "$HOME"/mylog.txt } But when I do something with an apostrophe in it, it comes up with some sort of prompt and does not log it properly. How do I escape all the text bei...
The problem you have has nothing to do with echo -e or your log() function. The problem is with apostrophes: log this is a testing's post The shell (bash, in your case) has special meanings for certain characters. Apostrophes (single quotes) are used to quote entire strings, and prevent most other kinds of interpol...
Escape characters from echo -e
1,448,891,626,000
I regularly use the expression line=${line//[$'\r\n']}. But what does [$'\r\n'] mean? I know it removes the '\r\n' characters but how does it do this? Does it remove the instances of both characters only, or does it also find matches of just one character? I do not understand the usage of this syntax. If you can, plea...
From the Bash manual: ${parameter/pattern/string} The pattern is expanded to produce a pattern just as in filename expansion. Parameter is expanded and the longest match of pattern against its value is replaced with string. The match is performed according to the rules described below (see Pattern Matching). ...
What does `[$'\r\n']` mean?
1,448,891,626,000
My desired outcome is the following: to recursively search a directory looking for a given string in all found files. The following command is my usual port of call: find ./ | xargs grep -ns 'foobar' However, when foobar has quotes the command fails and gives me a > prompt in the shell. The specific command that's ca...
Single quotes are terminated by single quotes; all other characters in between are preserved exactly as is, including backslashes. Thus there is no way to embed a single quote between single quotes. (But you can end the single quotes, escape a single quote, and start a new set of single quotes, as in 'Single quotes ...
How can I pass strings with single quotes to grep?
1,448,891,626,000
I'm seeing this in my .bashrc file: PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\ [\033[01;34m\]\w\[\033[00m\]\$ ' and I have absolutely no idea what all those escapes codes mean.
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 indica...
Understanding escape codes
1,448,891,626,000
I just struggled (again) over this: # only in bash NORM=$'\033[0m' NORM=$'\e[0m' # only in dash NORM='\033[0m' # only in bash and busybox NORM=$(echo -en '\033[0m') The goal is to include special characters in the string, not only for output using echo but also for piping into a cli tool etc. In the specific use ca...
What you want is "$(printf ...)". Stephane has already written an excellent expose of printf vs echo, more of an article than a mere answer, so I won't repeat the whole thing here. Keynotes pertinent to the current question are: Stick to POSIX features and it is very portable, and It is frequently a shell builtin, ...
Shell-independent escaping for strings in scripts
1,448,891,626,000
How do I print ↑ and ↓ in Unix? I have a script written in bash and I am printing some numbers with whom I want to print arrow keys to show increase/decrease. How do I literally print these arrow keys (let's say I assign them to some variable and print these along with my numbers) with my numbers using echo or printf ...
With bash 4.2 and above (or ksh, mksh, pdksh, lksh, zsh), you can use ANSI C Quoting: echo $'\U2191' or setting locale with unicode characters: LC_ALL=C.UTF-8 printf '\U2191\n' or you can use perl instead: perl -CS -le 'print "\x{2191}"'
How tp Print/echo arrow character (not key) in unix - bash, version 3.2.52
1,448,891,626,000
I have a list of files generated using find that I want to feed (pipe) to cp. My problem is that the files have spaces and apostrophes in them, leading cp to repeatedly complain that it "cannot stat". Is there an elegant solution to this problem?
Make sure you have -print0 in the find command. find . -print0 | xargs -0 cmd ...
How to copy a piped list of files contained spaces and apostrophes?
1,448,891,626,000
I can change my cursor shape like this: printf "\x1b[\x31 q" # block :) printf "\x1b[\x35 q" # ibeam :) But when I assign that to a variable with %s and expand using printf, it doesn't work: CURSOR="\x1b[\x3%s q" printf ${CURSOR} 1 # block :( printf ${CURSOR} 5 # ibeam :( How do I fix this?
\x31 is the character 1 and \x35 is 5, so in this case you don't have to use escape sequences. CURSOR="\x1b[%s q" printf "${CURSOR}" 1 printf "${CURSOR}" 5
Using printf with escape sequences?
1,448,891,626,000
When I execute the following command: #!/bin/bash while IFS= read -r -d '' file; do files+=$file done < <(find -type f -name '*.c' -print0) echo "${files[@]}" I do not get the same result as this one: #!/bin/bash find_args="-type f '*.c' -print0" while IFS= read -r -d '' file; do files+=$file done < <(find $...
(Note, you have a typo. You left off the -name flag in the second example.) One approach is to put the args in an array and pass the array appropriately to find... #!/bin/bash find_args=(-type f -name '*.c' -print0) while IFS= read -r -d '' file; do files+=$file done < <(find "${find_args[@]}") echo "${files[@]}" ...
Bash: escaped quotes in subshell [duplicate]
1,448,891,626,000
Example: When I run echo -e "\[\033[;33m\][\t \u (\#th) | \w]$\[\033[0m\]" the printed response is \[\][ \u (\#th) | \w]$\[\] where everything after the first \[ and before the last \] is an orangey-brown. However when I set the command prompt to \[\033[;33m\][\t \u (\#th) | \w]$\[\033[0m\] the command prompt ...
In Bash 4.4+, you can use ${var@P}, similarly to how ${var@Q} produces the contents of var quoted, see 3.5.3 Shell Parameter Expansion in the manual, bottom of page. $ printf "%s\n" "${var}" \[\033[00;32m\]\w\[\033[00m\]\$ $ printf "%s\n" "${var@P}" |od -tx1z 0000000 01 1b 5b 30 30 3b 33 32 6d 02 2f 74 6d 70 01 1b ...
Is it possible to use the escape codes used in shell prompts elsewhere, such as with echo?
1,448,891,626,000
Perl has a function called metaquote() to escape all special characters for a regular expression. Is there an equivalent technique for egrep? Example: If I am searching for the string abc.def.ghi, I need to remember to escape the dots manually, e.g., abc\.def\.ghi I assume egrep does not have a built-in mode/feature t...
Use the -F options to make grep treat pattern as fixed string: grep -F 'abc.def.ghi' <file And also note that you don't need to invoke egrep.
How to escape metacharacters for egrep like metaquote from Perl?
1,448,891,626,000
When running an interactive shell application, how can I send it a key (or key combination) which would normally be intercepted by GNOME Terminal? In this particular instance it's the F10 key which is intercepted. Bonus points for a general-purpose solution which would work for things like Alt, PgUp and Alt-Tab (might...
You can try disable the gnome shortcuts in Edit -> Keyboard shortcuts, so the window won't eat up the function keys. There seems to be a known gnome-terminal bug relating to this. Alternatively if this doesn't work, you will have to use another terminal that explicitly sends function keys as control codes to the termi...
How to bypass GNOME Terminal when sending keyboard input?
1,448,891,626,000
I'm trying to write a simple alternative script for uploading files to the transfer.sh service. One of the examples on the website mentions a way of uploading multiple files in a single "session": $ curl -i -F filedata=@/tmp/hello.txt \ -F filedata=@/tmp/hello2.txt https://transfer.sh/ I'm trying to make a function...
One way to avoid having bash word-splitting is to use an array to carry each argument without any need for escaping: push(){ args[${#args[*]}]="$1"; } build() { args=() for file do push "-F" push "filedata=@$file" done } build "$@" curl --progress-bar -i "${args[@]}" https://transfer.sh | grep...
posting data using cURL in a script
1,448,891,626,000
On CentOS 7 I am using cloud-init to spin off a droplet using the DigitalOcean API which requires YAML formatting. I got most parts working fine, but struggle on escaping the commands running at 'runcmd' below: #!/bin/sh set -e # Stop on first error curl -X POST https://api.digitalocean.com/v2/droplets \ -H 'Co...
You are using the single quotes for for the -d commandline options both for specifying strings separated by $variable as well as for quoting the argument for the second sed command. For $aAllowUsers SomeUser this might be what you want, but for /PermitRootLogin/s/^.*$/PermitRootLogin no/ this is probably not what you ...
How to escape in YAML the correct way?