简体   繁体   中英

Expect: How to iterate over files in a directory?

The following is a bash script which iterate over .csv files within a directory. The question is, I now have an expect script #!/usr/bin/expect where I want to use the same for loop. How could I achieve that?

#!/bin/bash
for f in /path/*.csv
do
echo $f
done

You would write:

#!/usr/bin/env expect
foreach f [glob /path/*.csv] {
    puts $f
}

Expect is an extension of Tcl. In addition to the expect man page, a link to the Tcl command documentation will be helpful: https://www.tcl.tk/man/tcl8.6/TclCmd/contents.htm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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