3

I'm writing a script in which I need to generate a tree of directories.

How to pass to tree a variable with list of directories to ignore? And those directories are with spaces in name.

I tried something like this:

tree -o /volume1/web/eb.html -T "List" --charset UTF-8 -C -I "$to_ignore" -P '*pdf' --prune --noreport /volume1/docs

Where vaiable to_ignore is a list of directories generated somewhere else by script:

'dir1|dir2|dir with space|dir4'

but that didn't worked. It crashed on dir with space.

Ok, so using quotes around variable helped with crashes but then tree prints even those directories that have required pdf files and are on list to ignore. And what's strange if I write those directories to ignore directly in my tree ... command than it works fine.

1 Answers1

3

Quote your variables:

$ tree foo                
foo
├── bar foo
│   └── blah
├── baz
│   └── blah
├── foo
├── foo bar
│   └── blah
└── yada

8 directories, 0 files
$ to_ignore='yada|bar foo|baz'
$ tree foo -I "$to_ignore"    
foo
├── foo
└── foo bar
    └── blah

3 directories, 0 files
muru
  • 72,889