X
X
xtala zen2016-11-01 22:46:25
linux
xtala zen, 2016-11-01 22:46:25

How to correctly assign Cyrillic to a variable in bash?

Hello. Those who work a lot in the Linux console and use Twitter may have heard/used the console utility for sending tweets -- twidge. The utility works flawlessly and honestly sends tweets to an authorized account, if not for one "but". In the usual case, the utility picks up one line shorter than 140 characters without a line break Привет мир! | twidge update. Actually, everything would be fine, but the idea came to my mind (probably not for me first) to enter tweets not by hand, but to use another Linux console utility for this - fortune , which produces a random quote.
fortune | twidge update, but as it turned out, when the line is moved, the tweet is considered finished and sent to the server. And fortunes usually consist of 2 or 3 lines. On the linux forum, they suggested this form of entry

fortune -sn140 | tr -s '[:space:]' ' ' | twidge update
Now the fortunes are not cut, because. Line breaks have been removed, but formatting is completely lost, which can ruin fortune, for example, with poetry. Having poked a finger into the sky a little, I came to the conclusion that you can try to output fortunes first to a file on your hard drive, and then through catassign the contents of the file to a variable, and feed the variable twidge update.
I sketched a simple bash script:
#!/bin/bash
config_file=$(cat test)
twidge  update "$config_file"

In order not to complicate the task, I didn’t start to output the fortune to a file yet, but simply created a file in my home folder testand scored the following text there:
bla
bla
Hello world!

Ran the script and it worked! Twidge sent the tweet with the text format saved, i.e. with line breaks.
But the joy was short-lived. Having scored a file text in Russian:
бла
бла
Привет Мир!

The console returned an error:
twidge: Enum.toEnum{Word8}: tag (1073) is outside of bounds (0,255)

And as I just didn’t pervert with quotes, it doesn’t want to accept a variable with Russian characters as input. Actually the main question is that perhaps someone knows the correct way (if any) of assigning a text in Russian to a variable in bash, so as to avoid this error. Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question