简体   繁体   English

bash脚本内期望代码内的增量数组索引

[英]bash script Incremement array index inside expect code

This is my code that I have embedded in some bash script. 这是我嵌入在某些bash脚本中的代码。

VAR=$(expect -c 'expect {  
       "name:" { send "'${Array[pos]}'"\r" ; exp_continue}  
       "hello" {send "hello\r" ; exp_continue}  
    } 

However the required value passed is a string that is stored in the array Array. 但是,传递的必需值是存储在数组Array中的字符串。 If it gets it wrong it will continue to ask for "name:", the correct value is always in Array. 如果输入错误,它将继续询问“ name:”,正确的值始终在Array中。 How can I incrememnt pos each time so that I will eventually hit the right entry? 我如何每次都能提高排名,以便最终找到正确的条目?

Thanks 谢谢

尝试${Array[pos++]} ,该值每次都会递增。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM