unix - 在期望脚本中获取多行输出
问题描述
我在文件中有以下代码,test.sh
它输出目录中的文件列表:
log_user 0
spawn sftp -oPort=22 username@hostname
expect "password:"
send "password123\n"
set prompt "sftp>";
set command "ls -l upload/External/*";
expect "$prompt" ;# wait for prompt
send "$command\r" ;# send command
expect "$command\r" ;# discard command echo
expect -re "(.*)\r" ;# match and save the result
puts "$expect_out(0,string)"
send -- "exit\r"
expect eof
然而,在执行时/usr/bin/expect test.sh
我只得到一行结果:
drwxrws--- 0 300096661 300026669 4096 Apr 13 19:48 upload/External/file1.csv
我尝试将 puts 命令更改为,puts "$expect_out(buffer)"
但它仍然是一样的。我期待该目录中存在的所有 5 个文件
解决方案
推荐阅读
- python - MySQL:无法在数据库中保存 utf8 字符
- cmake - 在命令行中设置 cmake 变量并将其与字符串进行比较
- cordova - 未验证vs代码断点中的Ionic 4 cordova android调试
- meteor - 如何获取服务器上的当前路由?
- c# - 链接异步/等待
- kubernetes - GKE:查看有关某人权限的详细信息
- php - 使用正则表达式检测字符串是否存在
- javascript - minDate 没有被设置?
- jquery - 如何在按钮单击事件中检查文件是否上传到 dropzone?
- java - 下载文件时 HttpUrlConnection 中的“IllegalsStateException closed”