Questions tagged [escape-characters]
Escape sequences such as encodings of terminal commands and function keys
453
questions
1
vote
1
answer
45
views
How to convert all newlines to "\n" in POSIX sh strings
I have a string that contains newline characters. I want to escape all newlines in that string by replacing all newline characters with a string of two characters: "\n". How can I do this in ...
0
votes
2
answers
60
views
groff -mandoc creating "ESC[1m" versus overstriking with backspace for bold text
I found that groff uses different ways to indicate bold text for the utf8 output format.
On FreeBSD 14, groff emits escape codes for a terminal (ESC, [1m):
$ printf ".Dd today\n.Sh NAME\n" | ...
0
votes
1
answer
44
views
How do I escape opening and closing brackets [] to use with cp command?
I have a script that finds some directories and then copies their content to another directory.
now the problem is that some of the found directories need to have brackets in their naming and they ...
0
votes
0
answers
83
views
Problem with Loading initial ramdisk in Archlinux (character firing)
In the boot arch initial (Loading initial ramdisk) some characters are appearing, photo below:
As well as when switching off, the same characters also appear, photo below:
However, sometimes (...
0
votes
0
answers
59
views
Properly escape a string variable that contains special characters to be used in a shell script?
I feel dumb for asking such a simple question but Im absolutely stuck on this one. I've search everywhere, tried several methods to escape or properly quote this variable, but no matter what when I ...
1
vote
1
answer
84
views
What do these strings, '\M^?' and '^\M?', represent in zsh/ZLE?
In the documentation for the Zsh Line Editor, there is a section that says:
For either in-string or out-string, the following escape sequences are recognised:
\a
bell character
\b
...
0
votes
1
answer
77
views
bash script creating string from number with plus sign
In a bash script, I stumbled over a simple looking problem of creating an expression from a parameter given as number and adding a plus + sign in front of it:
YEA= expr $2 \* 365
echo ${YEA}
pl="+...
-2
votes
1
answer
63
views
Understanding escapes used for changing text colour
I know that things:
To change the output text to red, I need output an escape code like \033[31m.
The \ is the escape.
The 033 is the ASCII escape code in octal.
But my question is, why I need to ...
0
votes
0
answers
73
views
Busybox support for ANSI escape codes?
I am working on some scripts that must run inside of initramfs. One of the scripts does an operation that takes a few minutes, so I want to display a nice progress bar that updates in-place, add in a ...
1
vote
1
answer
48
views
How can I make this command work in bash script? [duplicate]
Here is a command that works perfectly for me on the command-line:
find . -type f -exec grep -Hin --include=*.h --include=*.c 'somestring' {} \;
When I run the above command substituting the search ...
0
votes
0
answers
36
views
Truncate output to terminal width (colour and wide char aware) [duplicate]
I have the alias:
trunc='cut -c -${COLUMNS:-80}'
This works just dandy when text doesn't contain colours and wide characters.
I could play with tput rmam and tput smam, but these don't actually ...
0
votes
1
answer
244
views
How to escape characters inside variables in awk?
I'm trying to make a script that uses awk to get the recent file names from .config/okularrc and pipe them into dmenu, and back to awk to get the path for the name selected.
However, I'm getting an ...
0
votes
3
answers
143
views
Handle parentheses in this xargs multi-command
I suspect the following has been answered already but I don't know the terminology for the issue I'm having well enough to find an existing answer.
I'm working on a command to go through a list of ...
0
votes
1
answer
65
views
Problem with bash builtin bind and escaping
I'm trying to add a history fuzzyfind hotkey to my bash shell. However, my intended command gets cut in the middle:
[april@Capybara-2:~]$ cat ~/.bashrc
bind "\"\C-r\": \"\$(...
0
votes
1
answer
60
views
Font Effects in 8-Bit and 24-Bit Colour Representations
I want to use 8-Bit and 24-Bit colours in terminal, and have seen some different versions.
code="\e[38;5;${if}m"
code="\e[38;5;${ir};${ig};${ib}m"
I am unsure about the second ...
0
votes
0
answers
20
views
VT100/ANSI escape sequences [duplicate]
I'm trying to connect to a MUD. Problem is, that the color sequences aren't being interpreted. I get:
"[[0;36m~~[[1;32m"""""[[0;36m[[37m+[[1;32m"""[[0;36m~
...
0
votes
0
answers
23
views
Escaping Options in Bash Script That Works from CLI [duplicate]
This command works:
/usr/bin/scrot -f -scapture -e 'xclip -selection clipboard -t image/png -i $f'
This script does not:
#!/bin/bash
COMMAND="/usr/bin/scrot -f -scapture -e 'xclip -selection ...
3
votes
1
answer
1k
views
Why does escaping double quotes from Python's run (with shell=True) is different than in Bash?
I need to produce JSON configuration files
with echo and tee called from my Python script.
By trial-and-error I've found out that I have to use single quotes.
Yet I don't understand all the behaviour ...
0
votes
0
answers
35
views
How to escape command line to be able to send it by `ssh` to remote host in all cases?
I am composing command line for ssh with the following (Python) code:
def instrument(self, cmd: str) -> str:
return "ssh -A %s" % (cmd)
and this of course failing in some cases, for ...
0
votes
1
answer
132
views
ANSI escape sequences in PS1 cause incorrect length calculation [duplicate]
I have a PS1 set up in my .zshrc which includes multiple ANSI escape sequences. An equivalent definition works nicely in Bash, but in Zsh (v5.8.1) it seemingly causes the shell to calculate the width ...
3
votes
2
answers
527
views
Why does `htop` display `$'\t'` as `?` in `sort` command?
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 ...
2
votes
0
answers
543
views
Weird garbage (ansi escape characters?) in terminal when running VIM command
I have a script, that when run sometimes/often outputs an "unescaped" ANSI escape sequence when encountering this line:
vim -X -u NONE -c "helptags ~/.vim/plugged/vim-fugitive/doc" ...
1
vote
1
answer
686
views
echo -e \e does not print an escape from bash script on macos
I just moved to Mac. I'm using a shared shell script that's running in bash. The script itself works, however it is written to produce colored output, and that is broken.
Here's the first two lines ...
-1
votes
1
answer
313
views
Explain: echo -e "\e]52;;HelloWorld"
I think this is an OSC 52 statement and it will sent HelloWorld to the host clipboard if you use a OSC 52 supported terminal like Windows Terminal.
I also know that -e will enable interpretation of ...
0
votes
2
answers
123
views
Show quotes with echo inside bash -c
I am trying to echo I say "Hello, World!" with bash -c. This is (some of) what I have tried:
$ bash -c "echo I say \"Hello, World"'!'"\""
$ bash -c "echo I ...
0
votes
3
answers
217
views
How to interpret \e[H\e[2J ANSI escapes sequence from Linux terminal?
I'm asking again the question that was asked on StackOverflow with no answers I event added a bounty without an effect (I've just deleted that one). I think that people here may have better knowledge ...
1
vote
0
answers
105
views
Use altscreen like vim with screen with Ubuntu XTerm
When I exit a screen, I want to be able to return to the terminal looking as I left it. But right now, all I can do is have it clear the screen and put the terminal at the top or the bottom through ...
1
vote
0
answers
34
views
What the... Variable String [duplicate]
I believe I am running into a scenario where escaping quotes and utilizing variables as strings is causing some issues and after some hours of troubleshooting this isn't seeming to come to a ...
1
vote
1
answer
206
views
Strange escape sequences in terminal
I have kitty, and I use nnn as file manager.
I actiavted the "preview-tui" plugin in nnn.
When I hover over a folder, I see something like this:
What are those strange escape sequences?
0
votes
1
answer
114
views
How to make xterm recognize control-slash?
When I'm using an xterm, the keyboard sequence Ctrl+/ produces Ctrl-_. Here is the result of showkey -a when first hitting Ctrl+Shift+-, then hitting Ctrl+/. I am on a US ANSI keyboard.
[ ~ ] showkey ...
3
votes
0
answers
256
views
What is the meaning of ESC ( B ANSI escape code?
I'm working on the ANSI escape codes interpreter and I have this escape code from the top command.
[K
[7m PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND ...
0
votes
0
answers
256
views
mkdir - create directory (with ":" in its name) does not work in specific directory, works in others
I am trying to create a directory for a movie on my Plex media server and ran into a strange issue. When I try to make a directory with the movie name ("Borat: Cultural Learnings of America for ...
9
votes
3
answers
2k
views
Why do `ctrl+[` and `ESC` both produce `^[`? [duplicate]
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 ...
0
votes
1
answer
1k
views
Prevent splitting command line argument at spaces when running in bash script [duplicate]
I'm trying to run a command in a bash variable, like this:
cmd="python -m mymodule 'argument 123 456' argument2=32 argument3=234"
$cmd
It looks like it is splitting the command line ...
-4
votes
5
answers
5k
views
How do I create a file named \*\\'"Best School"\'\\*$\?\*\*\*\*\*:) on linux with touch command [closed]
I have had these issues for a while now. I've tried different approaches, all to no avail.
2
votes
2
answers
1k
views
Accurately overwriting previous lines of bash terminal output when text is wider than terminal (e.g. wraps mutliple lines)?
TL;DR - I know how to overwrite lines of output normally but none of the methods I've used previously (e.g. printf '\e[1A\e[2K') or have found online seem to work when the line being overwritten is ...
0
votes
1
answer
40
views
I am trying to understand what a particular echo statement does
I am trying to understand what the second echo statement does exactly (it's an existing script)..
echo "Triggering report.. "
curl -s -X POST "http://aaa.bbb"
echo -e \ '\
'
I ...
1
vote
0
answers
213
views
Is it possible to scroll arbitrary regions in a terminal?
I am researching the possibility of using an SSH connection for hosting a real-time, text based multiplayer game. It would be convenient for users to be able to type in "ssh mygame.com" and ...
0
votes
1
answer
71
views
zsh: How can I escape each word separately?
How can the following list of commands can be quoted separately?
s="cp
mkdir
[[
mv
rm"
quoted_s= ????
This should be the output of echo $...
4
votes
2
answers
890
views
How to run a loop inside sh -c
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 ...
1
vote
2
answers
1k
views
Bash - If press Esc when taking user string-input from "read" command, stop and then do other action
How can i get this feature to work?
Pressing Esc while taking inputs from the user will exit the script
read -r -p "Enter the filenames: " -a arr
if press Esc; then
read $round
...
0
votes
0
answers
18
views
zsh command expansion applies esacping [duplicate]
I have a string S, for which I want to replace every b character with \\ (two forward slashes).
So this is what I have:
$ S="abc"
$ A=$(echo $S | sed 's/b/\\\\/')
In bash I get the expected ...
0
votes
1
answer
270
views
VT100 Escape codes and TTY interaction: Why `open` a TTY device as opposed to using stdin/stdout
I had a look into escape codes and found some C code that reads the current cursor position. And I guess I have now stumbled over a topic of UNIX/POSIX programming I until now had not much exposure to....
0
votes
1
answer
26
views
Why menu options/items for editors/commands are declared with uppercase characters?
When nano is running, in the bottom appears the menu options based on ^#, for example
^O
^X
etc ..
Each one represents
ctrl + o
ctrl + x
respectively
Reason of this post: when a new linux user - ...
0
votes
0
answers
178
views
URL ampersand escape xdg-open command
I am trying to open a URL using the xdg-open command, but I have tried escaping the ampersand character to no avail; all possible choices don't work in bash.
I have tried the following
xdg-open "...
0
votes
1
answer
207
views
Bash alias with a loop, a sudo, pipes, flags, single quotes and double quotes
I want to make a bash alias of the following command, which works typed out on the command line but all my attempts at making an alias have failed. My only diagnosis is that all those nested quotes ...
3
votes
2
answers
214
views
How do I handle strange path characters when piping find output?
I had a problem where I wanted to find the length of each path from a find command. My first attempt was to run something like this:
find . -exec sh -c "echo {} | wc -c" \;
I got this idea ...
5
votes
6
answers
789
views
Convert to uppercase, except for escaped characters
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 ...
0
votes
3
answers
4k
views
bash insert backslash for every slash in string
I have a string that is a path:
/tmp/something
I need to escape the forward slashes with backslashes:
\/tmp\/something
How can I do this? Maybe sed?
Please point me in the right direction.
1
vote
2
answers
451
views
How to execute a string of bash command with command substitution
Suppose I have a bash variable like this:
tmp1='$(echo foo)'
or
tmp2='`echo foo`'
How to achieve foo as result?
I know that removing the command substitution from the string should work, but is ...