tmpfiles.d and spaces in filenames

Patrick O'Callaghan pocallaghan at gmail.com
Wed Jun 1 19:05:41 UTC 2011


On Wed, 2011-06-01 at 09:59 -0700, JD wrote:
> Since a space is Unix's and Linux's chosen field separator,
> I think having a space in filenames should be avoided. there
> are many situations where spaces in filenames cause problems.
> A simple example:
> 
> for i in *; do
> [ -f $i ] && echo $i is a file
> done
> 
> you will see that the file with spaces in it's name
> will not be recognized as a file because each
> space-separated member of that file name
> becomes a separate argument
> when * is expanded by the shell. 

No, each filename counts as one argument, even if it has spaces in it.
The problem arises when you *use* the argument. The above should read:

for i in *; do
[ -f "$i"] && echo "$i" is a file
done

(the quotes are optional in the echo case obviously).

poc



More information about the users mailing list