Дана 24/05/12 06:17PM, Alexis написа: > To deal with spaces etc., one could possibly use something along the lines > of the following kludge; it assumes that \n is relatively unlikely to be > found in a directory name, and that the directories in $dirs can be > separated by \n. > > cd "$target" && > echo "$(echo $dirs | while read dir > do > find $dir > done)\n" | sort | uniq > "$target_list"
When `while ... read ...` idiom is used, it is advisable to clear IFS to turn off field splitting, and use -r to avoid interpretation of backslash sequences in the input: while IFS= read -r dir; do # ... Back to parsing the output of ls(1) (also applicable to parsing the output of find(1), or globs), there is an indepth analysis of the problem at [1]. The accepted answer concludes that perhaps shell command language is not the right tool for the job, and a more sophisticated language should be used instead. While I don't agree with the author's choice of Python, any language supporting opendir(3), readdir(3) or equivalent functions will suffice. [1]: https://unix.stackexchange.com/questions/128985/why-not-parse-ls-and-what-to-do-instead