Skip to content

Instantly share code, notes, and snippets.

@dankogai
Last active December 24, 2021 06:58
Show Gist options
  • Save dankogai/79f77d365157ecbe63a88c4fe755f5d9 to your computer and use it in GitHub Desktop.
Save dankogai/79f77d365157ecbe63a88c4fe755f5d9 to your computer and use it in GitHub Desktop.
check if two paths are identical
#!/usr/bin/env perl
# cf. https://twitter.com/dankogai/status/1474270327006195718
use strict;
use warnings;
use feature 'say';
sub eqpath {
my @lhs = lstat( $_[0] ) or return;
my @rhs = lstat( $_[1] ) or return;
# if device numbers and inode numbers are the same, they are identical
return $lhs[0] == $rhs[0] && $lhs[1] == $rhs[1];
}
say 0+eqpath(@ARGV);
#!/bin/sh
# cf. https://twitter.com/0yama/status/1474270480895180805
lhs="$1"
rhs="$2"
test "$(stat -f '%d %i' $lhs)" = "$(stat -f '%d %i' $rhs)"
# echo $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment