Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [ $# -ne 3 ]; then
- echo "Usage: $0 force-y-or-n point-to symlink-goes-where" >&2
- echo "(order is just like ln -s)" >&2
- exit 1
- fi
- force="$1"
- ptr="$2"
- link="$3"
- if [ -h "$link" ]; then
- rm "$link"
- elif [ -e "$link" ]; then
- echo -n "Conflicting $link found... "
- if [ "y" = "$force" ]; then
- echo "moving."
- mv -i "$link" "$link.old" || exit 1
- elif [ "n" = "$force" ]; then
- echo "aborted.";
- exit 1
- else
- echo -n "Move out the way? (y/n): "
- read -r -n 1
- echo
- if [ 'y' = "$REPLY" ]; then
- mv -i "$link" "$link.old" || exit 1
- else
- exit 1
- fi
- fi
- fi
- # Ancient machines may not have the -r option, use readlink instead.
- # We'll just assume any failure is due to the bad option. If not, it'll
- # just fail again...
- ln -rs "$ptr" "$link" || ln -s "$(readlink -f "$ptr")" "$link" || exit 1
Advertisement
Add Comment
Please, Sign In to add comment