我想打开一个filelist.txt
只包含字符串${PATHFILE}/test.txt
的文件,读取该行并打开文件test.txt
。该文件test.txt
存在于文件夹~/testfile
中。
考虑这个示例代码:
#!/usr/bin/env tclsh
set PATHFILE "~/testfile"
set fp [open "filelist.txt" r]
set lines [split [read $fp] "\n"]
close $fp
foreach line $lines {
set fp1 [open $line r]
close $fp1
}
问题是“打开”命令似乎找不到PATHFILE
变量,我收到此错误:
couldn't open "${PATHFILE}/test.txt": no such file or directory
如果我尝试打开文件,set fp1 [open "${PATHFILE}/test.txt" r]
我没有任何错误。