Skip to content

Instantly share code, notes, and snippets.

@dbb
Created August 1, 2010 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbb/503684 to your computer and use it in GitHub Desktop.
Save dbb/503684 to your computer and use it in GitHub Desktop.
#!/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