1

I have a UNIX script which is supposed to scan all the folders and return the files older than speciific amount of time. I gave the logic as below, but the script is not able to read the folders with spaces. Can anyone please help on how to make this work?

dir='/a/b/test';

script is scanning all the sub directories after test, but not able to scan the directories with spaces, example 'test script'.

Karthik
  • 11

1 Answers1

2

So you have something like this:

$ foo='my dir'
$ ls $foo
my: no file or directory found
dir: no file or directory found

Instead, try this:

$ foo='my dir'
$ ls "$foo"

Or even better:

$ ls "${foo}"

Both of these methods shield the [:space:] character from being interpreted by the shell, and ensures that it is read as a [:space:] character, not the breaking point for a command.

It's a very good habit to get into when writing shell scripts!