我有一个shell环境变量PATH_TO_DIR
,我想在TCL脚本中检查文件$PATH_TO_DIR/target.txt
是否存在。
我目前的解决方案是:
catch {exec /usr/local/bin/tcsh -c "echo $PATH_TO_DIR/target.txt" } result
if {![file exists $result]} {
puts "ERROR: the file $result is not exists"
}
我确信有更优雅的方式 我怎样才能用TCL命令解决它?
答案 0 :(得分:3)
set path_to_dir $::env(PATH_TO_DIR)
set file_name [file join $path_to_dir "target.txt"]
set native_file_name [file nativename $file_name]
if {![file exists $native_file_name]} {
puts "ERROR: the file $native_file_name does not exist"
}