shell - 期望不适用于非英语语言
问题描述
解决方案
做了一个简单的测试,它对我有用(用5.45、8.5.9、10.15Expect
测试)。Tcl
macOS
[STEP 101] $ cat foo.sh
read -s -p 'Enter your パスワード: ' passwd
echo
echo "Your password is: $passwd"
[STEP 102] $ bash foo.sh
Enter your パスワード: foobar <-- manual input
Your password is: foobar
[STEP 103] $
[STEP 104] $ cat foo.exp
spawn bash foo.sh
expect {
"パスワード: $" {
send "foobar\r"
}
}
expect eof
[STEP 105] $ expect foo.exp
spawn bash foo.sh
Enter your パスワード:
Your password is: foobar
[STEP 106] $
我的语言环境信息:
[STEP 107] $ locale
LANG=""
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
[STEP 108] $
expect -d
:
[STEP 109] $ expect -d foo.exp
expect version 5.45
argv[0] = expect argv[1] = -d argv[2] = foo.exp
set argc 0
set argv0 "foo.exp"
set argv ""
executing commands from command file foo.exp
spawn bash foo.sh
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {84009}
expect: does "" (spawn_id exp6) match glob pattern "\u30d1\u30b9\u30ef\u30fc\u30c9: $"? no
Enter your パスワード:
expect: does "Enter your \u30d1\u30b9\u30ef\u30fc\u30c9: " (spawn_id exp6) match glob pattern "\u30d1\u30b9\u30ef\u30fc\u30c9: $"? yes
expect: set expect_out(0,string) "\u30d1\u30b9\u30ef\u30fc\u30c9: "
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "Enter your \u30d1\u30b9\u30ef\u30fc\u30c9: "
send: sending "foobar\r" to { exp6 }
Your password is: foobar
expect: read eof
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "\r\nYour password is: foobar\r\n"
[STEP 110] $
推荐阅读
- replace - 同时替换多个列值
- android - Retrofit2 未找到任何改造注释。(参数#1)
- python - 如何使用 MinMaxScaler sklearn 标准化训练和测试数据
- asp.net - IIS - 可以使用 localhost 访问端口 8080 的网站,但不能使用外部 IP 地址
- c# - 在 mvc 视图模型中获取当前操作
- android - 单击我正在调用异步任务的按钮时出错?
- ionic-framework - 如何使用 Ionic 3 永久保存数据?
- ios - 无法将“__NSCFNumber”(0x111189058)类型的值转换为“NSString”错误
- python - 极地标签区间 matplotlib
- html - 将单元格中的边框扩展到内容最高的单元格