I'm using the following sequence of commands in my .bashrc file to alter the appearance of my linux terminal. It fills the screen line by line with a pattern made out of characters. There is no abstraction, the characters are from a set within the command itself:
for i in $(seq 1 $(expr $(tput lines))); do echo -en '\E[0;32m'$(tr -dc '",.o;:~' < /dev/urandom | head -c $(tput cols)); done; tput cup 1
-->the set
The main idea is to read 80 cols (bytes) from some random characters from the set, and to print that * number of lines. Now, I've run the following contributed script in order to explore adding new characters to the set. To maintain compatibility with the linux terminal I'm using, I've run this outside of X etc, with the following result:
I'd like to to use the available characters in the sequence above. So I took many of them and did the following, for instance with ◘:
echo -n ◘ | hexdump
0000000 97e2 0098
0000003
so the UTF-8 sequence is \xE2\x97\x98
I build all the sequences I need: \xE2\x95\x99, \xE2\x95\x9a to f, \xE2\x96\x90 to 93
So I simply add to my .bashrc file A=$(echo -e '\xE2\x97\x98')
and B=$(echo -e ',.o;:~')
and I modify my command sequence like this (i.e. echo $A$B
):
for i in $(seq 1 $(expr $(tput lines))); do echo -en '\E[0;32m'$(tr -dc $(echo $A$B) < /dev/urandom | head -c $(tput cols)); done; tput cup 1
If I echo
$A or $B at the prompt, it prints the char(s). But when the sequence is called in .bashrc this mostly doesn't work at all. On an entire screen ◘ appears 3-5 times total along with many placeholder chars meaning the output is not supported by the term. The other characters from the set are there. Of interest is that if I kept the original syntax with no $B variable and simply tried to add $A to the set i.e. tr -dc '",.o'$A';:~'
I get the exact same sort of output, suggesting it's something else than syntax - because of /dev/urandom. Other variations on the syntax using quotations introduce more unrelated echo.
As a side note, in xterm, the result is similar with different placeholder chars, and a few ☗ and ◗.
Is there a way to bring the variable in the set like that or does this need to be redesigned from scratch to account for this case?
tr
works on bytes, not characters, you need anothertr
implementation like the heirloom toolchest's. Even then/dev/urandom
is not a source of valid UTF8, you'd want to take it as ucs2 or ucs4 and convert to utf8 first before feeding to tr – Stéphane Chazelas Dec 23 '13 at 12:20