[sf-lug] bash: identifying directories
ttrafford at gmail.com
Sat Jun 7 15:43:17 PDT 2008
Clyde Jones wrote:
> On Sat, Jun 7, 2008 at 11:37 AM, Asheesh Laroia <asheesh at asheesh.org> wrote:
> > On Tue, 3 Jun 2008, Matt Price wrote:
> >> another little scripting question:
> >> i'd like this tiny script i'm writing to scan the current directory,
> >> identify the subdirectories, and then do something in each of them. so
> >> in pseudocode:
> >> [find dirs]
> >> for DIR in $dirs ; do
> >> cd $DIR
> >> [do some stuff]
> >> cd ..
> >> done
> > As MP suggested, you use "find -type d" if you really want just
> > directories. But if you do that, you're going to end up accidentally sad
> > if there are spaces in their filenames, or intentionally careful to avoid
> > that problem.
> True - that is the purpose of setting the $IFS at the top of my script
> , that makes bash use the carriage return as a field delimiter
> instead of spaces plus carriage returns (you could set it to anything
> you want; tabs, commas, colons etc).
> However Michael correctly points out that bash will allow you to have
> a carriage return as *part* of the name (like the fscking "Icon<cr>"
> name on Macs), my script will specifically miss those directories.
'find' can return a zero delimited list, and then you could set
\0 isn't a valid character in a filename, is it?
A sect or party is an elegant incognito devised to save a man from
the vexation of thinking.
-- Ralph Waldo Emerson, Journals, 1831
More information about the sf-lug