1

I'm 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 aren't named such as:

fi@@lename&& or −filename or :−,?!drectoryanem!-

These special characters I couldn't handle, I changed the find script to:

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

but 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 couldn't handle these special file names, so I get many errors like find:

−."!filenda no such filename or directory
  • I couldn't duplicate this behavior on my system. What is your OS and what version of findutils do you have? – Joseph R. Oct 25 '13 at 11:47
  • my OS version is FreeBSD 3.2 it havent findutils, i use simple find – Ricsie Oct 25 '13 at 11:51
  • 4
    Is it a computer archaeology course? Why on earth would anyone teach csh scripting in the 21st century? – Stéphane Chazelas Oct 25 '13 at 12:07
  • csh/tcsh is a waste of time at this point. There are several better options. – slm Oct 25 '13 at 12:27
  • What should i learn instead of csh/tcsh? – Ricsie Oct 25 '13 at 12:30
2

In order to manage unusual filenames, you need to put quotes (") around them. However, it looks like you're not using find in the most efficient manner. One of the key parts of find is that it will do things to the files that are selected. So:

    find . -maxdepth 1 -type f -exec ls -l {} \;

will run everything after the -exec on every file that is found, replacing the {} with the filename.

Also, something is very strange if you are using FreeBSD 3.2 - it came out in May 1999.

  • Yes i know -exec, but in my case i need to count the lines of a file and sum them for each directory, so couldnt find a way how to do it in an exec, thats why i need always the path for the files and redirect them to wc and count them, – Ricsie Oct 25 '13 at 12:54
  • and FreeBSD 3.2 we use in school, so i need to use it althought its prehystoric – Ricsie Oct 25 '13 at 12:54
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.