The problem with the Cyrillic characters in the console

Sorry for the bad english. This is the Ruby code.

s = "" `touch #{s}` `cat #{s}` `cat < #{s}` 

Can someone say why it is not working? Via

sh: cannot open mi tick: no such file

But your code works fine

 s = "" `touch #{s}` `cat #{s}` `cat < #{s}` 

The problem is only that the Russian character "c" in the word and with symobol '<'

 woto@woto-work :/tmp$ locale LANG=ru_RU.UTF-8 LC_CTYPE="ru_RU.UTF-8" LC_NUMERIC="ru_RU.UTF-8" LC_TIME="ru_RU.UTF-8" LC_COLLATE="ru_RU.UTF-8" LC_MONETARY="ru_RU.UTF-8" LC_MESSAGES="ru_RU.UTF-8" LC_PAPER="ru_RU.UTF-8" LC_NAME="ru_RU.UTF-8" LC_ADDRESS="ru_RU.UTF-8" LC_TELEPHONE="ru_RU.UTF-8" LC_MEASUREMENT="ru_RU.UTF-8" LC_IDENTIFICATION="ru_RU.UTF-8" LC_ALL= woto@woto-work :/tmp$ ruby -v ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux] woto@woto-work :/tmp$ uname -a Linux woto-work 2.6.32-26-generic #48-Ubuntu SMP Wed Nov 24 10:14:11 UTC 2010 x86_64 GNU/Linux woto@woto-work :/tmp$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 10.04.1 LTS Release: 10.04 Codename: lucid 

Another example

Perhaps this will also be useful for understanding my problem.

 woto@woto-work :~/rails/avtorif$ touch  woto@woto-work :~/rails/avtorif$ ruby -e "`cat < `" woto@woto-work :~/rails/avtorif$ ruby -e '`cat < `' sh: cannot open  : No such file 
+4
source share
4 answers

This is a bug in dash , the shell that Debian uses by default (symlink /bin/sh leads to /bin/dash , and python os.system uses sh . Ruby probably also uses sh ). dash cannot parse 8-bit text correctly, including UTF-8. To work around this problem, replace it with bash :

 sudo dpkg-reconfigure dash 

and select "No." Thus, the system will use bash as the shell /bin/sh , which can handle UTF-8.

+1
source

The following works for me, have you tried it like this?

 s="" touch $s 

In bash, you are referencing a variable that adds a dollar sign.

0
source

In each of your examples, you execute a shell command. As a first step, I have to make sure that your shell command executes as you expect when you enter it directly:

 touch  cat  cat <  

If you get errors in the shell, this is one of two possibilities: the shell command does not understand the character encoding, or the file name needs quotation marks to distinguish it accordingly.

Ruby 1.9 understands character encodings that Ruby 1.8 did not. You will need to do a little research to determine which character your shell environment encodes. Once you do this, you will create the commands as normal lines:

 touch = "touch #{s}".force_encoding("UTF-8") ## or whatever encoding you need 

and then run the command:

 `#{touch}` 

I believe that the default encoding of Ruby 1.9 is UTF-8. Ruby 1.8 has no concept of coding, and a string is just an array of bytes. Unfortunately, not all pieces of software understand unicode or character encoding concepts (like Ruby 1.8). In these cases, the system will use everything that is encoded by default. I suspect your shell environment may be one of these programs.

0
source

use ruby ​​1.9 it has force_encoding methods in String object

-2
source

Source: https://habr.com/ru/post/1333570/


All Articles