Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [escape-characters]

Escape sequences such as encodings of terminal commands and function keys

62
votes
2answers
82k views

Why does Ctrl-D (EOF) exit the shell?

Are you literally "ending a file" by inputting this escape sequence, i.e. is the interactive shell session is seen as a real file stream by the shell, like any other file stream? If so, which file? ...
59
votes
11answers
67k views

How do I clear the Gnome terminal history?

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?
0
votes
3answers
511 views

Using `printf` to print variable containing `%` percent sign results in “bash: printf: `p': invalid format character”

I want to use printf to print a variable. It might be possible that this variable contains a % percent sign. Minimal example: $ TEST="contains % percent" $ echo "${TEST}" contains % percent $ printf ...
0
votes
2answers
36 views

Complex mouse inputs in XTerm

From the Xterm Control Sequences doc: Normal tracking mode sends an escape sequence on both button press and release.  Modifier key (shift, ctrl, meta) information is also sent.  It is enabled ...
-1
votes
2answers
94 views

How to make code interpret $ but not *? [closed]

I have some perl code (don't focus on what it does right now, i'm still working on it): #!/usr/bin/perl -w if(!@ARGV) { print ("ERROR: NO ARGS\n"); exit 1; } else { use Cwd qw(cwd); my $dir ...
2
votes
1answer
25 views

What does the leading part of Bash's default PS1 in Ubuntu mean?

This is the $PS1 of my Bash shell on a freshly installed Ubuntu 18.04: \[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\] \$ I can ...
0
votes
2answers
45 views

Using printf with escape sequences?

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=...
-1
votes
1answer
222 views

How to send ^D / EOT character to stdin of a shell process?

Suppose I have two shells open, one with PID 1234 and the other - 5678. I can clear the screen and reset of the other shell via echo $'\033c' > /proc/1234/fd/0 as if reset was typed on the prompt ...
1
vote
3answers
2k views

blink code(escape code) has been removed?

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, ...
1
vote
2answers
57 views

Escaping spaces in dash [duplicate]

I want to do something like this. $ touch a\ b $ cmd=cat\ a\ b $ echo $cmd cat a b $cmd cat: a: No such file or directory cat: b: No such file or directory There are problems with the spaces in the ...
0
votes
1answer
53 views

printf and echo -e are giving different results

I am using \0n escape sequence with echo -e and printf where n is the octal value of the ASCII character to be printed. When i used the statement echo -e "\0101" the shell is printing character A but ...
1
vote
2answers
122 views

How to key bind 'backward-kill-line' to Ctrl+Shift+Backspace?

I have used answer of zsh kill Ctrl + Backspace, Ctrl + Delete to configure following key binding: Ctrl+Backspace: delete until the beginning of current word, Ctrl+Delete: delete until the end of ...
1
vote
2answers
5k views

How can search for both single quotes and double quotes in a grep search?

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 ...
112
votes
2answers
9k views

Is Vim immune to copy-paste attack?

You should never paste from web to your terminal. Instead, you should paste to your text editor, check the command and then paste to the terminal. That's OK, but what if Vim is my text editor? Could ...
6
votes
1answer
241 views

Escape a mm/dd/YY backup date in a file name

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....
1
vote
1answer
43 views

Convert JSON with raw characters in string

Had a problem with a tool that was generating illegal JSON. Some of the JSON strings contained characters in the range 00-1f. So I wanted to convert these characters to correctly escaped valued \...
1
vote
2answers
34 views

Escape dots and asterisks in command line variable output string

I have a command that sets an environment variable from a command like this: BLACKLIST=$(python tools.py gen-blacklist) Which results in a string that contains dots * and asterisks *, like this: ...
1
vote
2answers
1k views

Programmatically detect the ANSI escape code supported by terminal

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 ...
0
votes
0answers
45 views

Escaping a string for a parameter inside a script [duplicate]

I have a shell script inside of which I call a command with several arguments. When I call the command from the terminal, the proper syntax is: command --foo='bar baz' Inside my script, I want to ...
3
votes
1answer
357 views

Understanding 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 ...
5
votes
3answers
3k views

Why is a single backslash shown when using quotes

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 ...
22
votes
4answers
10k views

Make Less highlight search patterns instead of italicizing them

To my understanding man uses less as a pager, and when searching for keywords using less it "highlights" keywords with italics. I find that really inconvenient, so I'd like to change this to something ...
0
votes
0answers
15 views

I am using Ubuntu and trying to minimize putty window from a bash script, are there any parameters or escape sequences?

For instance in order to maximize putty from command line someone stated (in this thread) that the escape sequence is '\e[9;1t' I wondering is there any sequence to minimize putty window? where can ...
10
votes
1answer
383 views

Do shells other than Bash and Zsh support ANSI-C quoting? e.g. $'string'

I have a shell script that uses the following to print a green checkmark in its output: col_green="\e[32;01m" col_reset="\e[39;49;00m" echo -e "Done ${col_green}✓${col_reset}" After reading about ...
2
votes
2answers
349 views

ESC-q doesn't work in tmux with zsh

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: the cursor just moves ...
64
votes
10answers
40k 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) ...
12
votes
2answers
5k views

How to determine the current color of the console output?

I know that, if a coloured terminal is available, one can colour the output of it using escape characters. But is there a possibility to find out, which colour the output is currently being displayed ...
3
votes
2answers
10k views

Meaning of backslash

Why the following command prints Smith but not \Smith? echo \Smith
0
votes
1answer
27 views

ANSI C quoting for tab and newline sometimes does not work

I am trying to use a newline in bash. I found that I need ANSI C quoting for that (i.e. $'\n'), but this often does not work for me. So I am wondering what I am doing wrong. # This works >> ...
35
votes
3answers
2k views

How do some tools (e.g. nano , less) manage to leave no content in terminals after exit? [duplicate]

Whenever I use a pager like less or an editor like nano in the shell (my shell is GNU bash), I see a behaviour I cannot explain completely and which differs to the behaviour I can observe with other ...
1
vote
2answers
66 views

how to properly schedule a task that schedules a task with 'at' (atd) ? or how to properly quote/escape in bash

I am looking for a way to create a command line using 'at' (atd) to schedule a task, that schedules a task to do "more stuff" after a reboot (one time task). What I am looking for right now is a way ...
0
votes
1answer
91 views

expansion with escape character

I am having trouble doing expansion with this because of the escape character. UNF\1122 Right now I am trying to stick with the really simple example of: ps -ef | grep $USER Eventually after I ...
3
votes
2answers
416 views

Unix Shell and colours

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"
1
vote
1answer
820 views

Double quotes issue in bash script

I have a shell script I am trying to get working. I need the output to be a certain way and I know I'm just not escaping the characters correctly. script: #!/bin/bash set -x DATE=$(date +%Y-%m-%d-%M)...
1
vote
1answer
638 views

Remote ssh commad with variables, quotes and single quotes [closed]

I need to execute a command on a remote MongoDB server, using variables declared on the shell script. Command: ssh root@10.1.1.1 "mongo mydb --host 10.1.1.1 --port 27017 -u user -p password --...
1
vote
0answers
65 views

Using a here-doc with trailing backslashes inside a process substitution in bash

This: cat <<EOF one two three EOF Prints: one two three And this: cat <<EOF one \\ two \\ three EOF Prints: one \ two \ three But while this: cat <( cat <<EOF one two ...
2
votes
2answers
3k views

Weird escape sequence

I need to identify what this escape sequences represents. I see this sequence is autogenerating on my server's console, but I'm not sure what is the reason for that. Escape sequence: ^[[[D I've ...
58
votes
5answers
154k views

How to escape quotes in shell?

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 ...
3
votes
1answer
159 views

BASH question: using read, can I capture a single char OR arrow key (on keyup)

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 ...
1
vote
2answers
95 views

How do I use shell commands with a directory that contains '-' like '-78059735'? [duplicate]

I have an external program that generates directories with strings that are negative integers. I am trying to use basic shell commands including cd and ls with this directory, for example: cd -...
1
vote
1answer
217 views

Stringify bash command from array of arguments for use in “bash -c”

I would like to stringify a given command, given as an array. This would be useful to for example put a command inside a bash -c. For example : cmd=( "printf '%s\n'" "foo bar" "baz bang" ) ...
0
votes
2answers
47 views

what is wrong with sed while using words starting with “w”

This works echo " HELLO x=10" |sed 's/ *\HELLO \+/HELLO /g' removes continuous space before hello and after word "HELLO" but this doesn't echo " WHERE x=10" |sed 's/ *\WHERE \...
29
votes
6answers
24k views

Is there any reason why I get ^[[A when I press up arrow at the console login screen?

Whenever I'm at the console login, I press up arrow intentionally to see the previously typed commands. But I see this ^[[A. But when I press Ctrl Alt Print Screen Scroll Lock Pause Break Page Up ...
3
votes
4answers
6k views

Bash converting path names for sed so they escape [duplicate]

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 ...
2
votes
1answer
168 views

Escape keywords with tmux send

Using tmux to send commands along from one terminal to another, I realize that $ tmux send -t mySession "text" ENTER correctly sends text, but $ tmux send -t mySession "up" ENTER sends text again, ...
5
votes
6answers
8k views

echo \\* - bash backslash escape behavior, is it evaluated backwards?

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 ...
1
vote
1answer
227 views

How to configure the system in order to be able to hear the sound of the \a escape character?

I read that if I execute: echo -e "\a" a sound emerges, but I executed this command several times and no sound happened.
-1
votes
3answers
1k views

Find: No such file or directory

Why does $ while true ; do 'date; time find /tmp/test -type f \ -exec cp /dev/null {} \;';sleep 3600; done not work and instead return an error message: -bash: date; time find /tmp/test -type f -...
0
votes
2answers
642 views

Passing an argument with double and single quotes to another call in bash [closed]

I have a call ./run.sh name --vars="service_name='someothername'" and I'm trying to call another program with exactly same --vars="service_name='someothername'" argument from run.sh, however when ...
8
votes
3answers
19k 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 HTTP_PROXY=...