Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell:Cyrillic vs select/case vs alignment_Shell_Cyrillic - Fatal编程技术网

Shell:Cyrillic vs select/case vs alignment

Shell:Cyrillic vs select/case vs alignment,shell,cyrillic,Shell,Cyrillic,假设我有一个简单的shell脚本,具有select/case结构和一些西里尔字母选项(#2)——如下所示: PS3='Please, your choice? ' options=( \ $'test test test' \ $'тест тест' \ $'test 2 test 2 test 2' \ $'тест 2 тест тест' \ $'test 3 test 3 test 3 test 3' \ $'A AAA' \

假设我有一个简单的shell脚本,具有select/case结构和一些西里尔字母选项(#2)——如下所示:

PS3='Please, your choice? '
options=( \
    $'test test test' \
    $'тест тест' \
    $'test 2 test 2 test 2' \
    $'тест 2 тест тест' \
    $'test 3 test 3 test 3 test 3' \
    $'A AAA' \
    $'BBB B' \
    $'CC CC' \
    $'DDDDD' \
    $'Quit' \
    )
select opt in "${options[@]}"
do
    case $opt in
~/Desktop> sh test.sh
1) test test test                  6) A AAA
2) тест тест               7) BBB B
3) test 2 test 2 test 2            8) CC CC
4) тест 2 тест тест        9) DDDDD
5) test 3 test 3 test 3 test 3    10) Quit
Please, your choice? ^C
然后,如果我运行它,它会奇怪地对齐选项--如下所示:

PS3='Please, your choice? '
options=( \
    $'test test test' \
    $'тест тест' \
    $'test 2 test 2 test 2' \
    $'тест 2 тест тест' \
    $'test 3 test 3 test 3 test 3' \
    $'A AAA' \
    $'BBB B' \
    $'CC CC' \
    $'DDDDD' \
    $'Quit' \
    )
select opt in "${options[@]}"
do
    case $opt in
~/Desktop> sh test.sh
1) test test test                  6) A AAA
2) тест тест               7) BBB B
3) test 2 test 2 test 2            8) CC CC
4) тест 2 тест тест        9) DDDDD
5) test 3 test 3 test 3 test 3    10) Quit
Please, your choice? ^C
但是,如果我在脚本中去掉俄语文本:

PS3='Please, your choice? '
options=( \
    $'test test test' \
    $'test test' \
    $'test 2 test 2 test 2' \
    $'test 2 test test' \
    $'test 3 test 3 test 3 test 3' \
    $'A AAA' \
    $'BBB B' \
    $'CC CC' \
    $'DDDDD' \
    $'Quit' \
    )
select opt in "${options[@]}"
do
    case $opt in
一切都会协调一致:

~/Desktop> sh test.sh
1) test test test                 6) A AAA
2) test test                      7) BBB B
3) test 2 test 2 test 2           8) CC CC
4) test 2 test test               9) DDDDD
5) test 3 test 3 test 3 test 3   10) Quit
Please, your choice? ^C
所以,我的问题是,是否有可能以某种方式修复它

以防万一,以下是我的设置:

~/Desktop> echo $LANG
en_US.UTF-8
~/Desktop> echo $LC_AL
en_US.UTF-8
~/Desktop> echo $TERM
xterm-256color

可能是版本问题;我可以复制你在4.1中的对齐方式,但它在4.2中看起来正确对齐。奇怪。。我在另一台机器上试用了
GNUBash,版本4.4.23(1)-发行版(x86_64-apple-darwin12.6.0)
,但它仍然没有对齐:(.我的4.1-vs-4.2测试是在macOS上进行的。(嗯,实际上是在Docker中。)直接在macOS中运行时,
bash
3.2和4.4中的对齐很好。请注意,
sh
是指向
/bin/bash
的链接,通常,
bash
的行为会有所不同,这取决于它是作为
sh
还是
bash
调用的。此外,
sh
将是您的系统默认值
bash
3.2,而
bash
是您本地安装的4.4。(不过,这些都不太相关,因为我在使用
sh
尝试您的脚本时,没有看到任何行为上的差异)旁注:为什么要用
$'
进行报价?这将启用ANSI-C报价,但您没有使用任何转义符。您应该可以只使用
'