tcsh scripting, problems with find and special characters in file names or directory names

StackOverflow https://stackoverflow.com/questions/19589187

  •  01-07-2022
  •  | 
  •  

Question

Im a beginner scripter, writing scripts in tcsh and csh(these are teached in my course)

Im writing a script which uses find for putting path of directories this is the part of the script:

set list = (`find $PATH -type d`)

it works fine until the file or directory names arent named such as: @fi@@lename&& or −filename or :−,?!drectoryanem!-``

These special characters i couldnt handle i changed the find script to:

set list = ("`find $PATH -type d`")

bit none of these works, when i want to use the path from the list in this next script:

foreach i ($list:q)
   foreach file (`find "$i" -maxdepth 1 -type f`)
   ....
   end
end

it couldnt handle these special file names, so i get many errors like find: −."!filename: no such filename or directory

Was it helpful?

Solution

I worked it out

It had to be this way:

set subor = ("`find "'"$i"'" -type f -maxdepth 1`")

now it ignores everything in the filenames

and in:

foreach j ($subor:q)

i quoted it this way it ignores the white characters in file names

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top