which package a file belongs to
kassube at gmx.net
Sun Jan 18 18:49:01 UTC 2009
Matthew Flaschen wrote:
> Nils Kassube wrote:
> > Matthew Flaschen wrote:
> >> Nils Kassube wrote:
> >>> dpkg -S /usr/bin/nedit|dpkg -l $(cut -f1 -d':')
> >> Doesn't work. But:
> >> dpkg -l `dpkg -S /usr/bin/nedit|cut -f1 -d':'`
> >> would.
> > Sorry, I don't understand why it shouldn't work. Here both commands
> > have the same output.
> Nothing is being passed to the cut command, so first you get:
> cut: -: Input/output error
> then dpkg -l gets no other parameters so prints everything.
Now its getting interesting :)
Actually I had tried the command supplied by the OP and tested what the
output was. I didn't fully evaluate the logic of the command sequence.
Then I modified the command to the version I posted and tested that
version and the output was what I expected.
While your explanation seems logical, the command did work on my machine.
Therefore I made some tests to find out how the shell works with
pipelines and command substitution:
In a new directory make a file first:
$ touch test
How does ls works with a pipe?
$ echo hello | ls
Good - like I expected, ls ignores the hello from the pipe. Now, how does
the combination with a command substitution work?
$ echo hello | ls $(cut -f1)
ls: cannot access hello: No such file or directory
OK, so the command substitution reads the pipeline and ls gets the output
of the command substitution.
> Note, this is actually tested.
Like I wrote above, I have tested my version also and here it works. Could
it be that you don't use bash but some other shell? I made the test on my
Kubuntu 8.04 machine first and then I verified that the result is the
same with the Ubuntu 8.10 LiveCD.
More information about the ubuntu-users