[Nottingham] "unescaping" the wildcard character for xargs

Martin martin at ml1.co.uk
Tue Jun 19 12:15:45 UTC 2012


On 19/06/12 12:30, Rory Holland wrote:
> Let's say I have a command which outputs line-delimited filenames with
> wildcards in them.
> 
> For example:
> 
> /home/alice/*
> /home/bob/*
> /home/eve/*
> 
> I'm trying to cat these files, but using the following doesn't work
> 
> <command> | xargs cat
> 
> This is because the * character is being interpreted literally, so I
> get the following error on each line:
> 
> cat: /home/alice/* : no such file or directory.
> 
> Nothing in man xargs seems to help. What can I do?


The "*" needs exposing to bash or whatever shell for "globbing" to be
done by the shell for whatever your current working directory is...


One awkward trick would be to use:

<command> | while read a ; do echo $a ; done | xargs cat


That works fine provided there are no spaces or other "interpretable"
characters in your names.


Hope that helps,
Martin

-- 
- ------------------ - ----------------------------------------
-    Martin Lomas    - OpenPGP (GPG/PGP) Public Key: 0xCEE1D3B7
- martin @ ml1 co uk - Import from   hkp://subkeys.pgp.net   or
- ------------------ - http:// ml1 .co .uk/martin_ml1_co_uk.gpg



More information about the Nottingham mailing list