[Cialug] shell escaping with command substitution?

Scott Yates Scott at yatesframe.com
Tue Feb 10 00:15:33 CST 2015


Have a closer look at the file names.  I suspect you might have some odd
characters in there.

Midnight Commander might help here

--------------------------------
~/test *❯❯❯* cat <(./testpgm)

the square boxes normally indicate unprintable characters I think.

On Tue, Feb 10, 2015 at 12:03 AM, Pixie <pix at kepibu.org> wrote:

> On 2015.02.09 21:41, 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.
>
> Command substitution[1] isn't a straight textual replacement that hooks
> back into the normal shell parser, it does a limited subset of things
> afterwords--namely word splitting[2] followed by glob expansion.  In
> other words, no parsies the quotesies.
>
> Relevantly, this[3] popped up on Hacker News earlier today.  (My
> takeaway?  Use Perl, it'll be less painful.)
>
> [1]
> http://www.gnu.org/software/bash/manual/bashref.html#Command-Substitution
> [2] http://www.gnu.org/software/bash/manual/bashref.html#Word-Splitting
> [3] http://www.dwheeler.com/essays/filenames-in-shell.html
>
> _______________________________________________
> Cialug mailing list
> Cialug at cialug.org
> http://cialug.org/mailman/listinfo/cialug
>


More information about the Cialug mailing list