Skip to content
Advertisement

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

Advertisement

Answer

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

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement