I want a bash function to count for the String Width that will comsumed when display.
because in my cases, String may contain some wide-charactors (e.g. Chinese). So I cannot just use the length of a string.
function getDisplayWidth ()
{
???
}
Then “abc” will return 3
and “前后” should return 4 instead of 2.
If your implementation of
wchas the-Loption, that appears to count the right “thing”. (Coreutils has it, not sure if any other do.)Ex: