Created
August 1, 2010 19:46
-
-
Save dbb/503684 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
# get a command name, or bail out if the user didn't supply one | |
my $name = $ARGV[0] or die "must supply a command name"; | |
# get the 'which' output for the user-supplied command name | |
chomp( my $which_output = `which $name` ); | |
# get the 'file' output from the path gathered above | |
my $file_output= `file $which_output`; | |
# put the initial 'which' output in the string to be printed later | |
my $output_string = $which_output; | |
# instantiate a variable that will be used in the while loop | |
my $new_path; | |
# while the 'file' output contains 'link' inside word boundaries | |
# note: this will NOT match 'linked', which appears in the output | |
# of some binaries | |
while ( $file_output =~ /\blink\b/ ) { | |
# get the path name from the 'file' output | |
if ( $file_output =~ /`(.*)'/ ) { | |
$new_path = $1; | |
} | |
# add an arrow plus the modifed 'file' output | |
$output_string .=" -> $new_path"; | |
# update the file output, and check it again | |
$file_output=`file $new_path`; | |
} | |
print "\n$output_string\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment