[Cialug] shell escaping with command substitution?

Daniel A. Ramaley daniel.ramaley at drake.edu
Tue Feb 10 09:01:50 CST 2015


Does testpgm output 1 long line of single-quoted filenames? I'm asking 
this seemingly silly question because i'm not sure what e-mail wrapping 
may have done to your command output.

If it is possible to modify testpgm, then it might be easier to have 
testpgm output one filename per line, without the quotes. Then you can 
process the files with a while loop:
    ./testpgm | while read FILE ; do cat "${FILE}" ; done
As someone else posted, you might also be able to use xargs; the while 
loop here is more typing but can be useful for other situations such as 
if you want to run multiple commands on each file instead of just a 
simple "cat".

On 2015-02-09 at 21:41:14 Kenneth Younger wrote:
> Alright, a basics question, because apparently my shell-fu isn't
> strong enough to figure this out:
> 
> I have a command I wrote, testpgm. When ./testpgm is run it outputs
> this:
> 
> '/Users/kenny/test/test 3.txt' '/Users/kenny/test/test1.txt'
> '/Users/kenny/test/test2.txt'
> 
> When I then run cat $(./testpgm), I get errors. If I copy and paste
> the output instead of doing command substitution, it works fine. What
> gives? This is the error:
> 
> cat: '/Users/kenny/test/test: No such file or directory
> cat: 3.txt': No such file or directory
> cat: '/Users/kenny/test/test1.txt': No such file or directory
> cat: '/Users/kenny/test/test2.txt': No such file or directory
> 
> It almost seems like it's double-escaping the output of testpgm.
> 
> Thanks in advance for any insights.
> 
> -Kenny
__
Daniel A. Ramaley  |  Network Engineer 2
Drake Technology Services (DTS) | Drake University

T: +1 515 271-4540
F: +1 515 271-1938
E: daniel.ramaley at drake.edu



More information about the Cialug mailing list