Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

6 votes
2 answers
881 views
Why does 'cal' use weird 08 / ^H / \b terminal code for highlighting and how does that work?
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 0000020 W e T h F r S a \n 0000030 1 2 _ \b _ \b 3 0000040 4 5 \n 6...
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 0000020 W e T h F r S a \n 0000030 1 2 _ \b _ \b 3 0000040 4 5 \n 6 7 0000050 8 9 1 0 1 1 1 2 \n 0000060 1 3 1 4 1 5 1 6 1 7 1 0000070 8 1 9 \n 2 0 2 1 2 2 0000080 2 3 2 4 2 5 2 6 \n 2 7 0000090 2 8 2 9 3 0 00000a0 \n 00000b0 \n 00000bc As you can see, there is an invisible sequence being printed of _\b _\b before the '3' that is highlighted for today. _ being underscore (5F in ascii hex) and \b being Ctrl-H or 08 in ASCII hex. What is this? I know there are a lot of obscure terminal codes, but I would expect it to use something more standard like \e[7m. What is even stranger is that I can't reproduce the same behavior of cal by printing out the same characters using standard printf functions like one of these commands: /usr/bin/printf "1 2 _\b _\b3 4 5\n" /usr/bin/printf "1 2 _^H _^H3 4 5\n" Where ^H is made by pressing Ctrl-V Ctrl-H. But neither of these produce the same inverse video output that cal does. I even tried writing a little C program to do it too. I've also tried with echo -e. The interesting thing is that while it doesn't reverse the video in the terminal, if I pipe the output from less -R, it changes its color to yellow and underlines it. On other terminals I tried it just underlines it. It almost seems like overstriking, but if I use a character other than _ it doesn't work, which makes me think that _\b is a single code sequence. And how does the video for that character then get inversed? Any insight into this? The man page says that the output of cal is supposed to be a bit for bit compatible version to the original Unix cal command. So I can only assume this is some ancient code.
deltaray (1477 rep)
Nov 3, 2016, 06:32 PM • Last activity: Mar 25, 2024, 10:30 AM
24 votes
2 answers
9314 views
How do I find number of vertical lines available in the terminal?
I'm writing a script which shows the `git log` for a directory when I `cd` into it. Such a log can be overwhelming, containing hundreds of lines. So far I have been limiting that to a hard-coded 30 lines with (`... | head -n 30`), cool on the big screen at Work, too big at home. I would prefer the l...
I'm writing a script which shows the git log for a directory when I cd into it. Such a log can be overwhelming, containing hundreds of lines. So far I have been limiting that to a hard-coded 30 lines with (... | head -n 30), cool on the big screen at Work, too big at home. I would prefer the log to take up about half the (vertical) screen on any terminal, e.g. Gnome at work, iTerm2 at home. I do not use screen or tmux. But would like to learn them. How do I find the number of vertical lines available in a terminal from command line?
jalanb (598 rep)
Feb 10, 2015, 01:10 PM • Last activity: Feb 21, 2024, 03:44 AM
1 votes
2 answers
13124 views
How can I make flashing text in bash?
In the script bellow, how can I make the the word "end" from the output of the command " `printf "\e[41mend==>\e[m $i` "", flashing? #!/bin/bash in=path_to_my_folder for i in $(cat ${in}/file.txt); do Command 1; Command 2; . . . . Command N; sleep 60 echo "Review command stats summary" printf "\e[41...
In the script bellow, how can I make the the word "end" from the output of the command " printf "\e[41mend==>\e[m $i "", flashing? #!/bin/bash in=path_to_my_folder for i in $(cat ${in}/file.txt); do Command 1; Command 2; . . . . Command N; sleep 60 echo "Review command stats summary" printf "\e[41mend==>\e[m $i " done
user88036
Aug 6, 2015, 05:56 PM • Last activity: Jun 2, 2022, 01:09 PM
3 votes
1 answers
150 views
Which terminals or terminal emulators support hardware windows?
terminfo(5) manual page describes a set of capabilities `wnum` (maximum number of definable windows), `cwin` (define a window), `wingo` (go to window), `wind` (resize current window), but only one terminal definition in terminfo master file uses any of them (tvi9065; it sets wnum=0). Do any hardware...
terminfo(5) manual page describes a set of capabilities wnum (maximum number of definable windows), cwin (define a window), wingo (go to window), wind (resize current window), but only one terminal definition in terminfo master file uses any of them (tvi9065; it sets wnum=0). Do any hardware terminals, or terminal emulators, exist that support these capabilities?
sendmoreinfo (2711 rep)
Sep 12, 2017, 06:18 PM • Last activity: Sep 6, 2021, 09:12 PM
6 votes
2 answers
7723 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 unparsed gunk unexpectedly, which I'm assuming means my terminal (on Mac OS) doesn't support that esca...
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, despite having read in a number of places that these mean the same thing: 27 = 033 = 0x1b = ^ = \e In searching I found [this question about detecting slash-escaped support . The selected answer sniffs the $TERM value to detect case $TERM in (|color(|?))(([Ekx]|dt|(ai|n)x)term|rxvt|screen*)*) PS1=$'\e\]0;$GENERATED_WINDOW_TITLE\a'"$PS1" esac But I wonder how reliable that is. Is there a standard way to check for escape code support (primarily for Bash), or is that script pretty much the run of the mill? - Alternatively, what escape code can I use to 'guarantee' the most wide-spread support? - What about echo expansion -e? - What are general best practices in terms of portability/availability/distribution for **scripts** that use or reference control codes? This is a nice read too for anyone else looking for info.
qodeninja (729 rep)
Oct 6, 2014, 11:05 PM • Last activity: Mar 8, 2021, 10:57 AM
3 votes
5 answers
7420 views
blink code(escape code) has been removed?
According to [Bash tips: Colors and formatting (ANSI/VT100 Control sequences)][1] 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. [1]: http://misc.flogisoft.com/bash/tip_colors_and_formatting
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.
PersianGulf (11308 rep)
Mar 15, 2016, 12:21 AM • Last activity: Nov 15, 2019, 02:51 AM
14 votes
1 answers
3024 views
What type of encoding do these ANSI artworks use?
I've found [this website](https://fuel.wtf/packs/fuel27/); it has zip files (links on [the main page](https://fuel.wtf/)) with all the artworks. Some of them have an `.ans` extension and they look like ANSI escape codes used on Linux/Unix, but when I open one of them using `cat` in the XFce terminal...
I've found [this website](https://fuel.wtf/packs/fuel27/) ; it has zip files (links on [the main page](https://fuel.wtf/)) with all the artworks. Some of them have an .ans extension and they look like ANSI escape codes used on Linux/Unix, but when I open one of them using cat in the XFce terminal it produces garbage (but in color). They don't look like the image gallery. The first line of the main artwork from the link looks like this (copied from Emacs): [0;1m[30mthere is no substitute [0;33mÜܲ[1;43m°±²²[40mÛ[43mÛ²±[0;33mÝ ßÜ[1;43m²²²[40mÛÛ²[40m[K The file type is DOS, but they can be just created on Windows. When searching for ANSI art I also found [this website](http://www.roysac.com/roy_bestof.html) that has zip files containing only files with an .ans extension and they also don't render properly on Linux (gallery on page 2). My questions are: * what type of encoding is this, for what computer? * do I need a special viewer to see it on Linux terminal? * do you know if this type of artwork was created for Linux/Unix terminals? I've only found ASCII art. * is it possible to convert it to be viewed on Linux terminals?
jcubic (10310 rep)
Oct 15, 2018, 07:46 AM • Last activity: Nov 12, 2019, 02:42 PM
0 votes
0 answers
112 views
How do I add characters to the ANSI terminal so that the user can move their cursor through them?
Specifically, I want to do something like this: ``` aaaaaaaa_ ``` Where the cursor can move through the `a`s.
Specifically, I want to do something like this:
aaaaaaaa_
Where the cursor can move through the as.
kkeey (111 rep)
Oct 28, 2019, 05:44 PM • Last activity: Oct 28, 2019, 06:12 PM
7 votes
0 answers
507 views
Colorize the PS4 prompt?
With the option `set -x`, each command is echoed to STDERR before execution, prefixed by the expanded `$PS4`, with the first character being repeated according to the call stack depth. I want the output of the `$PS4` prompt to be colorized. I.e. where (set -x; ls -l) will currently print + ls -l I w...
With the option set -x, each command is echoed to STDERR before execution, prefixed by the expanded $PS4, with the first character being repeated according to the call stack depth. I want the output of the $PS4 prompt to be colorized. I.e. where (set -x; ls -l) will currently print + ls -l I want an output \033[90m+ ls -l\033[0m \ \ \ `- Reset color `- Muted gray However, with PS4 being printed before echoing the command, I can't think of a method to reset the color with \033[0m *before* the command is executed. Is it possible to do this somehow?
kdb (229 rep)
Oct 14, 2019, 10:55 AM
3 votes
1 answers
1200 views
Emacs ansi-term with zsh: error in process filter. Invalid face: unspecified
I have the latest stable versions of Emacs (24.3) and of Zsh (5.0.2). I can run Zsh without problem from a terminal (e.g. ITerm2), but if I try to run it from `M-x ansi-term` I get the error: `Emacs ansi-term with zsh: error in process filter. Invalid face: unspecified` This is the case even if I st...
I have the latest stable versions of Emacs (24.3) and of Zsh (5.0.2). I can run Zsh without problem from a terminal (e.g. ITerm2), but if I try to run it from M-x ansi-term I get the error: Emacs ansi-term with zsh: error in process filter. Invalid face: unspecified This is the case even if I start M-x ansi-term with bash and then I try to switch to zsh. This is all on Mac OS X. Any thoughts on what may be causing this and how to overcome it?
Josh (1784 rep)
Sep 30, 2013, 04:11 AM • Last activity: Sep 17, 2019, 07:08 AM
1 votes
1 answers
5200 views
Colour Errors / Warnings / Information in bash script
So I have the following variables defined in `/etc/bash.bashrc`: RS="\033[0m" # reset HC="\033[1m" # hicolor UL="\033[4m" # underline INV="\033[7m" # inverse background and foreground FBLK="\033[30m" # foreground black FRED="\033[31m" # foreground red FGRN="\033[32m" # foreground green FYEL="\033[33...
So I have the following variables defined in /etc/bash.bashrc: RS="\0330mecho -e "$FRED Red" *at the prompt*, I actually get Red in red on gnome-terminal, but when I execute: #!/bin/bash echo -e "$FRED Red" echo -e "$FYEL Yellow" echo -e "$FGRN Green" I get everything in the default colour even though $TERM is xterm-256color. [screenshot including exact output" class="img-fluid rounded" style="max-width: 100%; height: auto; margin: 10px 0;" loading="lazy"> *What am I doing wrong?* **Note:** Eventually I want to echo Errors in red, Warnings in yellow and Info in green in my scripts.
Fabby (5549 rep)
Nov 17, 2018, 12:13 PM • Last activity: Nov 17, 2018, 01:37 PM
2 votes
0 answers
621 views
ANSI Colors when using Systemd Service
I have setup a server for [SSHTron](http://sshtron.zachlatta.com), a game which can be played by ssh-ing into a `sshtron` server. Color matters a lot in this game. I can run the ssh server by running the executable I got: `./sshtron-server` And it worked fine, the users were able to play the game in...
I have setup a server for [SSHTron](http://sshtron.zachlatta.com) , a game which can be played by ssh-ing into a sshtron server. Color matters a lot in this game. I can run the ssh server by running the executable I got: ./sshtron-server And it worked fine, the users were able to play the game in color mode. ssh sshtron.myserver.com I wanted to make a service so that it starts automatically if my system restarts. But when I did, and the users were seeing the game without colors. The following is my sshtron.service file: [Unit] Description=SSHTron [Service] Type=simple WorkingDirectory=/home/pi/go/src/zachlatta/sshtron ExecStart=/home/pi/go/src/zachlatta/sshtron/sshtron-server [Install] WantedBy=multi-user.target **UPDATED:** I tried to wrap the server in a *Docker* container as well, but the result is same, no colors. :( **UPDATED:** Looks like we need to find a way to allocate a pseudo-tty and run sshtron over it, using systemd.
Ali Yousuf (121 rep)
Mar 21, 2017, 08:30 PM • Last activity: Mar 27, 2017, 06:50 AM
1 votes
2 answers
2077 views
M-x ansi-term colors in Emacs 24.x
I have noticed that some colors in `LS_COLORS` don't work when running a shell inside `M-x-ansi-term` in Emacs. For exmaple; di 00 94 is supposed to turn on bold on light blue on directories on `LS_COLORS` (see a list of the codes [here][1]), but `ansi-term` in Emacs does not show it in color. In fa...
I have noticed that some colors in LS_COLORS don't work when running a shell inside M-x-ansi-term in Emacs. For exmaple; di 00 94 is supposed to turn on bold on light blue on directories on LS_COLORS (see a list of the codes here ), but ansi-term in Emacs does not show it in color. In fact, only the simple colors listed on that website seem to work under ansi-term in Emacs, while they work perfectly well on my regular gnome terminal. Is there a way to get ansi-term to recognize the so called **extra** colors? Where/how can I look up the colors supported by ansi-term in Emacs?
Amelio Vazquez-Reina (42851 rep)
Sep 20, 2012, 08:07 PM • Last activity: Nov 7, 2016, 09:38 AM
1 votes
1 answers
1686 views
Screen caption custom colors
I am having trouble customizing the color of my caption in screen. I can use the 8 standard colors supported (as well as their brighter versions), but I am unable to define a custom color. The docs for screen state: "[Colors are coded either as a hexadecimal number or two letters][1]". It does not s...
I am having trouble customizing the color of my caption in screen. I can use the 8 standard colors supported (as well as their brighter versions), but I am unable to define a custom color. The docs for screen state: "Colors are coded either as a hexadecimal number or two letters ". It does not seem to define anywhere what format to write the hex number in. I have tried several random ways but so far none seem to work. Does anyone know how to use a custom color in screen?
MrGlass (111 rep)
Dec 4, 2013, 03:10 PM • Last activity: Oct 3, 2016, 09:01 PM
8 votes
2 answers
5501 views
What's the right value of $TERM for emacs' ansi-term, especially if 'eterm-color' isn't available after SSH?
I'm currently setting `$TERM` to `xterm-256color`: if [[ -n "$EMACS" ]]; then export TERM=xterm-256color alias emacs="emacsclient --no-wait" export EDITOR="emacsclient --no-wait" export VISUAL="emacsclient" fi I used to have it set to `eterm-color`, but the problem is that this terminal type is not...
I'm currently setting $TERM to xterm-256color: if [[ -n "$EMACS" ]]; then export TERM=xterm-256color alias emacs="emacsclient --no-wait" export EDITOR="emacsclient --no-wait" export VISUAL="emacsclient" fi I used to have it set to eterm-color, but the problem is that this terminal type is not available on most of the machines I log into via SSH. The default .bashrc in Ubuntu checks if the TERM variable starts with xterm-, in which case it tries to set the window title: PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" The problem is the \[\e]0; bit. It should be parsed by xterm-compatible terminal emulators, but emacs (ansi-term) doesn't do that. The result of which is a terminal like this: 0;user@host: ~user@host:~$ It also breaks some applications using readline, when the typed text is larger than the width of the terminal. Because eterm-color isn't available on some remote hosts (and I can't install it either), setting it to that value messes up things like less. Is there any trick I can use, such as another terminal type that ships with most distributions or a hack that makes ansi-term recognize the relevant escape codes and set the title, or just discard them?
Stefano Palazzo (598 rep)
Sep 23, 2013, 07:49 AM • Last activity: Sep 24, 2016, 11:28 PM
3 votes
1 answers
1327 views
Convert screen log to html
I would like to log actions made in a terminal window, and convert the log to html on fly. I already tried commands script/screen + [ansi2html](https://pypi.python.org/pypi/ansi2html), but the result is not perfect: the escape sequences for line editing is not handled correctly, so in the resulting...
I would like to log actions made in a terminal window, and convert the log to html on fly. I already tried commands script/screen + [ansi2html](https://pypi.python.org/pypi/ansi2html) , but the result is not perfect: the escape sequences for line editing is not handled correctly, so in the resulting html I have a mixture for the old and the new version of the line. So if the output of the terminal is like $> echo Original text Original text $> echo Other Other The resulting html is
 $> echo Original text
 Original text
 $> echo Othernal text
 Other
Any idea, how to solve the issue?
Attila Szlovencsák (131 rep)
Sep 21, 2013, 10:06 PM • Last activity: Aug 26, 2016, 11:26 PM
9 votes
2 answers
7628 views
How to use ESC sequences to make terminal region scrollable
I have a stm32f1 controlled device that uses USART/USB port to implement a user control interface. Using a standard terminal software (putty/minicom) a user has an ability to enter simple command in device shell. There is a problem. In case of many incoming info packets, they print over shell prompt...
I have a stm32f1 controlled device that uses USART/USB port to implement a user control interface. Using a standard terminal software (putty/minicom) a user has an ability to enter simple command in device shell. There is a problem. In case of many incoming info packets, they print over shell prompt making entering new commands hard. I plan to split a terminal screen on two areas: a one line prompt and a scrollable area for incoming packets. I have tried to use the following escape sequence: 162 72 r * DECSTBM - Set top and bottom margins (scroll region on VT100) [4;20r = Set top margin at line 4 and bottom at line 20 but still can not find a good tutorial which is described a right way that will help me to solve my problem.
Ruslan Popov (191 rep)
Nov 23, 2014, 10:21 AM • Last activity: May 25, 2016, 11:52 PM
3 votes
1 answers
2179 views
Passing escape sequences to shells within ansi-term in Emacs
In a regular terminal (e.g. iTerm2 on OS X) I can connect to a database, e.g. > psql .... and then, as I type my command in `psql`, e.g. $ select foo from bar I can move around (as I type psql commands) using the standard `Alt+b` and `Alt+f`. However, if I try to do this in a shell within Emacs (`an...
In a regular terminal (e.g. iTerm2 on OS X) I can connect to a database, e.g. > psql .... and then, as I type my command in psql, e.g. $ select foo from bar I can move around (as I type psql commands) using the standard Alt+b and Alt+f. However, if I try to do this in a shell within Emacs (ansi-term), it doesn't work. More specifically, if I start a shell (e.g. Bash) within ansi-term, the keystrokes Alt+b and Alt+f work fine in the Unix shell (in this case, Bash), **BUT** if I then drop into psql from within the shell, the keystrokes Alt+b nor Alt+f stop working (the keystrokes won't move the cursor, and I can't keep typing commands properly anymore) Why is this? And how can fix this behavior? ## Update 1: I narrowed the problem and the line in my .zshrc that causes this behavior is the following one: TERM=xterm-256color I have this line because its's the best solution that I found to fix the problem that I report in this thread: Emacs multi-term not displaying special characters correctly ## Update 2 (solution, but why?): I found the solution in this thread: Weird character zsh in emacs terminal . As the top answer says, I had to create eterm-color terminfo by using following command: (note that the terminfo path may be different from your system) # If you use Cocoa Emacs or Carbon Emacs tic -o ~/.terminfo /Applications/Emacs.app/Contents/Resources/etc/e/eterm-color.ti
Amelio Vazquez-Reina (42851 rep)
Jan 29, 2014, 09:40 PM • Last activity: Apr 21, 2016, 10:57 PM
4 votes
2 answers
620 views
Graphical console applications in Emacs
I am having trouble running [`htop`][1] 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 control characters. Is there a way to have `ansi-term` work with graphical console applications?...
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 control characters. Is there a way to have ansi-term work with graphical console applications?
Amelio Vazquez-Reina (42851 rep)
Dec 6, 2012, 01:20 AM • Last activity: Mar 27, 2016, 05:56 PM
2 votes
1 answers
695 views
Maximizing tmux session shows weird ANSI Sequences
I have a tmux session inside Putty. It was fine for past many months, but now I see a strange thing. When I maximize a normal Putty window, and if cursor is not on a new line, then I get some weird ANSI Sequences in the shell. Eg, I maximized 4 times to get: 0;44;8m 0;46;8m 0;50;8m 0;55;9m It happen...
I have a tmux session inside Putty. It was fine for past many months, but now I see a strange thing. When I maximize a normal Putty window, and if cursor is not on a new line, then I get some weird ANSI Sequences in the shell. Eg, I maximized 4 times to get: 0;44;8m 0;46;8m 0;50;8m 0;55;9m It happens only on maximize, not on restore. If cursor is on a new line, then the codes printed start with "^[[<", & then the ANSI Sequences. Eg, when I maximised 4 times, ensure that the cursor is on a new line, I got: ^[[<0;64;8m ^[[<0;138;8m ^[[<0;95;8m ^[[<0;79;7m What is happening ? I restarted the session and issue is not happening now. How to debug next time it happens ?
Prem (3385 rep)
Jan 14, 2016, 10:15 AM • Last activity: Jan 14, 2016, 11:04 AM
Showing page 1 of 20 total questions