Saturday, February 13, 2010

Handling Filenames with Spaces in Bash

Handling Filenames with Spaces in Bash

(본문중에서)
This is a quickie. On the Mac you regularly handle files with spaces in the Finder without issue, and even on the command line when you put quotes around it or let tab-completion escape it properly. However, if you try to do things in a shell script, like a for loop, on filenames that involve a space you’re going to hit a wall. For splits items on a space, regardless of it they’re quoted (if they’re stored in a variable). However, the read command does not. Observe.

find ~ -name '* *' | while read FILE
do
echo $FILE rocks.
done

And that’s that. Run the command and pipe to the while stanza and it works like a charm.

참고 :
여기에도 비슷한 것이 있음
Handling Filenames With Spaces

No comments:

Post a Comment