Last active
December 24, 2021 06:58
-
-
Save dankogai/79f77d365157ecbe63a88c4fe755f5d9 to your computer and use it in GitHub Desktop.
check if two paths are identical
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 | |
# 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); |
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
#!/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