Use of find in unix on strange file/directory names Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Use of find in unix on strange file/directory names without wasting too much if your time.

The question is published on by Tutorial Guruji team.

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

Answer

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

We are here to answer your question about Use of find in unix on strange file/directory names - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji