Skip to content

Instantly share code, notes, and snippets.

@Miciah
Created October 24, 2016 17:06
Show Gist options
  • Save Miciah/4207efa653fe677031062229d7d3dd6a to your computer and use it in GitHub Desktop.
Save Miciah/4207efa653fe677031062229d7d3dd6a to your computer and use it in GitHub Desktop.
#!/bin/bash
for fn
do
declare -A seen
while [[ -h "$fn" ]]
do
if [[ -n "${seen[$fn]}" ]]
then
printf 'Cycle detected; terminating.\n'
break
else
seen[$fn]=1
if [[ -h "$fn" ]]
then
target="$(readlink "$fn")"
printf '%s -> %s\n' "$fn" "$target"
fn="$target"
fi
fi
done
if ! [[ -e "$fn" ]]
then
printf '%s does not exist.\n' "$fn"
else
ls -ld "$fn"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment