public
Created

  • Download Gist
full-command-path.pl
Perl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#!/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";

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.