Data.ByteString.Char8
is almost never the right choice if you want to deal with non-ASCII text. It will mangle your data. In your case you probably should use Data.ByteString.UTF8
instead (provided you use a UTF-8 locale, which is the case for most modern desktop Unix-y OSes).
Example of Data.ByteString.Char8
mangling data:
Prelude Data.ByteString.Char8> "été"
"e\769te\769"
Prelude Data.ByteString.Char8> unpack $ pack "été"
"e\SOHte\SOH"
Prelude Data.ByteString.Char8> Prelude.putStrLn "été"
été
Prelude Data.ByteString.Char8> Prelude.putStrLn $ unpack $ pack "été"
ete
Use Data.ByteString.UTF8.toString
and not Data.ByteString.Char8.unpack
.
These invocations
let s = toString $ bytes $ bash $ fromString "мама.sh"
runCommand s
runCommand $ "ls -l " ++ s
work for me from within ghci ("мама.sh"
is a shell script with some Cyrillic characters in the name).
Of course if you escape the entire command it will also escape the white space and it will not work. Escape each word of the command individually.