[Gllug] shell quoting problem

Alain Williams addw at phcomp.co.uk
Wed Jul 2 09:47:13 UTC 2008


A little problem that is rearing its head more and more since some of my clients
insist on creating files with spaces in the names. An example that happened just
now:

I wanted to find files that had 'John Smith' as part of the name and 'ls' them.

	ls -l $(locate 'John Smith')
Doesn't work since the spaces are interpretted as argument separators - as I expected.

	ls -l "$(locate 'John Smith')"
Doesn't work since ls looks for a big long file name with embedded \n in it.

The simplest that I can achieve is:

	(IFS=: ; ls -ld $(locate 'John Smith' | tr '\n' : ))

It is interesting that the above works (with spaces round '-ld') and that I don't
have to go:

	(IFS=: ; ls:-ld:$(locate 'John Smith' | tr '\n' : ))

I was just wondering if there was anything simpler and completely obvious that
I had overlooked ?


Answers preferably something that will work in bash & ksh.

Cheers

-- 
Alain Williams
Linux Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
+44 (0) 787 668 0256  http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php
Chairman of UKUUG: http://www.ukuug.org/
#include <std_disclaimer.h>
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list