LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Quick questions about pipe redirection (https://www.linuxquestions.org/questions/linux-newbie-8/quick-questions-about-pipe-redirection-4175420670/)

kostis* 08-06-2012 11:54 AM

Quick questions about pipe redirection
 
Hi!
I've been reading a bit about bash and came upon the ldd command. I thought I'd try it with vlc to see the dependencies. Of course I needed the path to the vlc executable first, which i got with "which vlc". This outputs "/usr/bin/vlc" as a string that I could type (or copy) as an argument to ldd. Then I thought, why should I go through the trouble and not use "which vlc|ldd" instead? After all isn't this what pipe redirection is for; Passing the output of the first command as an argument to the second? I also tried "which vlc|ldd -" but that didn't work either. Am I missing something or is it just that ldd doesn't work that way?

spazticclown 08-06-2012 12:08 PM

The program has to be capable of receiving the information from the pipe. It looks to me (through basic testing) that ldd doesn't like that.

However this should work:
Code:

ldd $(which vlc)
What this does is call ldd and executes the which command as the input.

Give it a try.

Habitual 08-06-2012 12:09 PM

edit:
spazticclown types faster than I.

kostis* 08-06-2012 12:15 PM

Thanks for the quick replies. I hadn't thought of this approach. It works indeed, and so does "ldd `which vlc`" which also executes the command and feeds the result to ldd. Is there an advantage to one approach or the other or is it just a matter of preference?

spazticclown 08-06-2012 01:58 PM

The method with `` is the first method I learned and works fine for everything I have done. With $(), from my understanding, is a more recent way of doing it and is a lot easier to see what is going on when scanning large amounts of code, however it may only work in bash or korn shells.

If anybody has more info on this than I can provide I would be interested in it as well (links etc).

chrism01 08-06-2012 06:29 PM

Basically, the backquote method `` is the original style on Unix eg BSD, Solaris, HP-UX, AIX etc.
The $() is newer and I think(?) probably only since the later version of ksh or possibly since the advent of Linux.
Its as well to recognise both if you work in the commercial environment.


All times are GMT -5. The time now is 03:51 AM.