The escape-characters tag has no wiki summary.
11
votes
3answers
3k views
Removing control chars (including console codes / colours) from script output
I can use the "script" command to record an interactive session at the command line. However, this includes all control characters and colour codes. I can remove control characters (like backspace) ...
7
votes
4answers
2k views
How to make the terminal display user@machine in bold letters?
I have seen in some screen-shots (can't remember where on the web) that the terminal can display the [username@machine /]$ in bold letters. I'm looking forward to getting this too because I always ...
7
votes
2answers
1k views
inline double and single quote escaping
I'm having trouble with escaping characters in bash. I'd like to escape single and double quotes while running a command under a different user. For the purposes of this question let's say I want to ...
6
votes
4answers
1k views
How to clear terminal completely?
When we use clear command or Ctrl+L in terminal, it clears terminal but we can still scroll back to view the last used commands. Is there a way to completely clear the terminal?
6
votes
2answers
1k views
Where do my ANSI escape codes go when I pipe to another process? Can I keep them?
I sometime want to pipe the color-coded output fror a process, eg. grep... but when I pipe it to another process, eg. sed, the color codes are lost...
Is the some way to keep thes codes intact ?
...
6
votes
2answers
610 views
How do I background an SSH session? [duplicate]
Possible Duplicate:
How can I break away from an SSH session that has crashed?
I have started an SSH session on the command line, but now I want to get back to my local command line. For ...
6
votes
2answers
707 views
How to avoid escape sequence attacks in terminals?
Reading the details of CVE-2009-4487 (which is about the danger of escape sequences in log files) I am a bit surprised.
To quote CVE-2009-4487:
nginx 0.7.64 writes data to a log file without ...
5
votes
4answers
1k views
How can I create a file with multiple lines from the command-line?
How can I enter the following contents in a file:
Hi
abcd
I tried using echo "Hi\nabcd" >> ab.txt, but in the file it's written as is (the \n is included, instead of a newline)
5
votes
1answer
1k views
export HTTP_PROXY and special characters in passwd
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 ...
4
votes
5answers
116 views
How to use ' in alias?
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 ...
4
votes
1answer
496 views
How can I match the page break character in a regular expression?
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?
4
votes
2answers
291 views
is it possible to send a control sequence to a terminal emulator using the keyboard
If you type echo -e '\eZ' and hit return in a shell running in an xterm, you'll see that the terminal emulator prints an obscure code 1;2c. This seems to indicate that xterm interprets the VT100 ...
4
votes
1answer
64 views
how to escape “\”in ssh-copy-id?
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 ...
4
votes
1answer
335 views
Re-escape brackets in PS1
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 ...
4
votes
2answers
264 views
DEC ANSI command sequence questions; cursor movement
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 ...
3
votes
2answers
722 views
Passing a bash command-line argument containing a dot
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 ...
3
votes
2answers
323 views
Unix Shell and colours
Can any one please help me understand this code snippet that I found in .profile file
echo -en "\e[32;44m $(hostname) \e[m";echo -e "\e[m"
3
votes
3answers
2k views
How can I pass strings with single quotes to grep?
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'
...
3
votes
1answer
250 views
Could someone please explain some of these escape codes?
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 ...
3
votes
2answers
694 views
Trying to print up down arrow keys
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
...
3
votes
2answers
53 views
Can I make grep treat escaped multiline as a single line?
How can I make tools like grep treat multilines escaped with a backslash as a long single line?
Let's say I have some files that looks like this:
testvar=test1 \
test2 \
test3
...
3
votes
1answer
402 views
Reverse control-code look up for terminals
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 ...
3
votes
1answer
520 views
How to bypass GNOME Terminal when sending keyboard input?
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 ...
3
votes
2answers
128 views
Change colors in console/virtual terminal
Is there a way to alter all the available colors in console / virtual terminal?
By console, I mean what you get after pressing CTRL + ALT + F1 and not anything like xterm or urxvt. So, I guess that ...
3
votes
1answer
131 views
Printing colored text using script
When I type below command in the shell I get the OUTPUT in green color.
Command
echo "\033[32mCONNECTING TO abpwrk\033[m";
Output(in green color)
CONNECTING TO abpwrk
But if I use the same ...
3
votes
1answer
293 views
Escape sequences in output of script called from ncurses application
I'm currently running mcabber as my Jabber client (which uses ncurses) in a tmux session on my homeserver. Locally i run iTerm2 as a terminal emulator, which supports the triggering of growl ...
2
votes
3answers
45 views
Where do I find a list of terminal key codes to remap shortcuts in bash?
For example:
"\e[1;5C"
"\e[Z"
"\e-1\C-i"
I only know bits and pieces, like \e stands for escape and C- for Ctrl, but what are these numbers (1) and letters (Z)? What are the ;, [ and - signs for?
...
2
votes
2answers
262 views
How to copy a piped list of files contained spaces and apostrophes?
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". ...
2
votes
1answer
178 views
Trouble in script with spaces in filename
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 ...
2
votes
1answer
541 views
In Bash, why is PROMPT_COMMAND set to something invisible?
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
...
2
votes
2answers
470 views
How to escape < or > in a parameter in shell?
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 <?
2
votes
1answer
140 views
How to capture text formatting in bash?
The following shell script works but removes colored formatting generated by rspec:
#!/bin/bash
OUTPUT=`rspec`
echo "$OUTPUT"
How to preserve the colors?
2
votes
1answer
50 views
How can a bash script detect support for window titling escape characters?
I have a debug trap that runs every time I enter a command in bash that sets the window title to indicate what command is running. I'm leaving out all the configuration details and boil it down to:
...
2
votes
1answer
53 views
Confused about when to escape metacharacters in pathnames
I'm pretty confused about under which circumstances do I need to escape metacharacters in pathnames. Consider the following example:
I'm in the following working directory:
$ echo $PWD
...
2
votes
1answer
168 views
Is there a way to lock terminal's title?
Sometimes there're lots of different sessions opened in own terminal's tabs and it's rather desirable to have theirs initial titles (named by session name) locked since local title tweaks make those ...
2
votes
2answers
60 views
Calling bash from sh (dash) with commands read from args, and “Unterminated quoted string”/“unexpected EOF”
Just thought I'd document this: I'm trying something very simple - set env variable in bash, and print it out:
$ bash -c "a=1; echo a$a;"
a
$ bash -c "a=1; echo a\$a;"
a1
Now I'd want this same ...
2
votes
1answer
195 views
Shell escape characters for sh -c
I need to execute a command with escaped argument(s) using sh -c. I know the string looks pretty ugly but simple ones don't cause a problem.
The output of the echo when passed to sh -c is different ...
2
votes
2answers
332 views
Is the `\` character escaping or becoming part of my ssh key password
If I do:
ssh-keygen -N password123\$ -f bobskeys
Is \ escaping the $ character or becoming part of the password?
Or rather, will bash be doing any escaping before ssh-keygen gets the password ...
2
votes
1answer
127 views
Modifying a set of binary files
I have several binary files with the character 0x04 in them, and I'd like to add an escape \ character before each. Is there a script I can use to do this without needing to manually edit each one?
2
votes
1answer
660 views
Backspace, del, arrow keys not working with interactive programs in Tilda
I currently run Openbox on a light netinstall of Debian. In Tilda, when I use a program like nslookup or winexe, some of my keys do not work properly.
Backspace generates ^?
Up generates ^[[A
...
2
votes
1answer
478 views
Escaping of meta characters in basic/extended posix regex strings in grep
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 ...
2
votes
1answer
95 views
Graphical console applications in Emacs
I am having trouble running htop within an ansi-term in Emacs 24.2. It looks like some of the control characters are not interpreted correctly.
I thought ansi-term was capable of handling font ...
1
vote
2answers
71 views
How to print shell variables and values to be able to copy/paste them?
In Bash 4.2.25, the set and env output is not escaped, so shell escapes and any non-printable characters won't be copy-pasteable. Take for example this shell session:
$ export foo=$'a\nbar=\baz'
$ ...
1
vote
1answer
456 views
Opening a file with space from Ruby
When I need to progmatically open in emacs a file that has a space in its name, how can I do that? I've tried these commands from a Ruby script, inside backquotes or popen(…):
emacs "foo bar"
or
...
1
vote
1answer
75 views
How to prevent double escaping?
I'm trying to put a bunch of images together into a pdf. I ran gm convert *.jpg out.pdf and it worked, but the images were not in the right order.
I found that ls -v orders them correctly so then I ...
1
vote
2answers
187 views
Convert discus output into readable HTML mail
How can I take the DISCUS command output below:
and convert it into something HTML email friendly? I've bash scripted something like this:
#!/bin/sh
discus > /tmp/discus.log
touch ...
1
vote
2answers
247 views
bash scripting - Any function to escape character?
I am trying to automate some of my stuff and facing a issue, the problem boils down to escaping the value that is being passed as a argument to the script.
myScript.sh
#!/bin/bash
loadPatch -name ...
1
vote
2answers
83 views
How to escape text in awful.util.spawn_with_shell command?
Based on a suggestion, I've now got the following call in rc.lua:
awful.util.spawn_with_shell('vlc $(xclip -o)')
How do I ensure that the output of xclip is escaped so that space characters are not ...
1
vote
1answer
67 views
Apostrophe appearing as space
I am trying to insert the following message:
friend's mobile number
from a file over redhat server into sql server 2005.
this message is appearing in the sql server as below:
friend s mobile ...
1
vote
0answers
103 views
ESC-q doesn't work in tmux with zsh
The title says it all. I use Escq a lot (stashing the current line while I execute another command), and it works fine with Gnome Terminal 3.6.0 + zsh. However, if I start tmux, then it stops working: ...