Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8473195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:16:57+00:00 2026-06-10T17:16:57+00:00

I have a file contain lines with path to the files. Sometimes a path

  • 0

I have a file contain lines with path to the files. Sometimes a path contain SHELL environment variable and I want to check the file existence.
The following is my solution:

set fh [open "the_file_contain_path" "r"]

while {![eof $fh]} { 
  set line [gets $fh]
  if {[regexp -- {\$\S+} $line]} {
    catch {exec /usr/local/bin/tcsh -c "echo  $line" } line
      if {![file exists $line]} {
        puts "ERROR: the file $line is not exists"
      }
  }
}

I sure there is more elegant solution without using

/usr/local/bin/tcsh –c

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:16:58+00:00Added an answer on June 10, 2026 at 5:16 pm

    You can capture the variable name in the regexp command and do a lookup in Tcl’s global env array. Also, your use of eof as the while condition means your loop will interate one time too many (see http://phaseit.net/claird/comp.lang.tcl/fmm.html#eof)

    set fh [open "the_file_contain_path" "r"]
    
    while {[gets $fh line] != -1} { 
      # this can handle "$FOO/bar/$BAZ"
      if {[string first {$} $line] != -1} {
        regsub -all {(\$)(\w+)} $line {\1::env(\2)} new
        set line [subst -nocommand -nobackslashes $new]
      }
    
      if {![file exists $line]} {
        puts "ERROR: the file $line does not exist"
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file and I want to remove some lines that contain
I have a text file I want to read, but exclude lines that contain
I have a file that contain lines that looks like this: >AF001546_1 [88 -
I have a file in UTF-8, where some lines contain the U+2028 Line Separator
I have a file which contains lines of data in the following format: a11
I have an LPTSTR for a file path, i.e. C:\Program Files\Ahoy . I would
I have a text file (lets call it file1.txt), it contains the following lines:
I have a text file that contains the path to multiple files in the
I have one file (for example: test.txt), this file contains some lines and for
I have a file that might contain a line like this. A B //Seperated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.