开发者

this one-line shell script not working on Mac - any ideas how to fix?

开发者 https://www.devze.com 2022-12-25 08:59 出处:网络
This unix command I haven\'t got quite working on Mac yet - any ide开发者_如何学Goas what needs adjusting:

This unix command I haven't got quite working on Mac yet - any ide开发者_如何学Goas what needs adjusting:

find . | grep  '.*\(css\|js\|rjs\|rhtml\|rb\)$' | sort | while read in; do printf "\n\n####\n# FILE: %s\n####\n\n" ${in} >> onebigfile; cat "${in}" >> onebigfile; done

thanks


The purpose of this command is to gather the content of all the files under the current directory whose names ends as said (css ... rb) in a file named onebigfile (with delimiters) IIUC.

To debug this type of series of piped commands, you can run the individual commands, or individual groups of commands to try to see what is happening. For instance, try:

find .
find . | grep  '.*\(css\|js\|rjs\|rhtml\|rb\)$'
find . | grep  '.*\(css\|js\|rjs\|rhtml\|rb\)$' | sort

Then get one line of the output (for example ./dir/file.css), and try:

echo './dir/file.css' | while read in; do echo ${in}; done
echo './dir/file.css' | while read in; do cat ${in}; done
echo './dir/file.css' | while read in; do cat ${in} >> onebigfile; done

You should bo able then to understand what's happening.

The problem may be due to file and directory names containing spaces. The solution in this case is to use find -print0 command.

0

精彩评论

暂无评论...
验证码 换一张
取 消