I was trying to find all symbolic links in /usr/lib and use file on the first entry in the list, which I delimited with head -n 1.

Why does find /usr/lib -maxdepth 1 -type l | file $(head -n 1) work but find /usr/lib -maxdepth 1 -type l | head -n 1 | file does not?

It complains that I am not using file correctly. Probably because it lacks an argument, but - programmatically/syntactically - why can’t file grab it’s argument from the pipe?

  • Piatro
    link
    fedilink
    English
    arrow-up
    20
    ·
    23 days ago

    Your syntax is fine, but not all commands/programs accept input from the pipe, or more accurately from stdin. Looking at the man page for file (https://www.man7.org/linux/man-pages/man1/file.1.html) I can’t see a stdin option, so you have to pass each of the files from your head output as arguments to file.

    • emotional_soup_88OP
      link
      fedilink
      English
      arrow-up
      7
      ·
      23 days ago

      Thanks! Yeah, I just came to the realization that this was more about my lack of understanding of the file command than anything else.

    • N0x0n@lemmy.ml
      link
      fedilink
      arrow-up
      6
      ·
      23 days ago

      I learned this the hardway with ffmpeg… In my defense… Their documentation IS huge !!!

      Kinda interested if 2>&1 would also work in this case?

      • theit8514@lemmy.world
        link
        fedilink
        arrow-up
        11
        ·
        23 days ago

        2>&1 pipes stderr to stdout, which would not affect a binary like file which doesn’t parse stdin. You would need something like xargs file which would convert the stdout to command line arguments.

        • N0x0n@lemmy.ml
          link
          fedilink
          arrow-up
          2
          ·
          23 days ago

          Thanks for the clarification :)) still new the all the bash syntax and always interested to hear what more skilled people have to say !