lnrel 763 B

1234567891011121314151617181920212223
  1. #!/bin/bash
  2. fn=""
  3. test "$#" -ge 2 && fn="$2"
  4. test "$#" -ge 1 || { echo "Usage: /path/to/create/link/on/./relative/path/to/link/to [linkname [extra args]]" ; exit 0 ; }
  5. test "${1#./}" = "$1" && test "${1#*/./}" = "$1" &&\
  6. { echo "./ not present in path" ; exit 1 ; }
  7. linkat="" ; linkto="${1#./}"
  8. test "$linkto" = "$1" && { linkat="${1%%/./*}/"; linkto="${1#*/./}"; }
  9. test -z "$linkto" && { echo "What do I link to?" ; exit 1 ; }
  10. baseto="$(basename "$linkto")"
  11. test -z "$fn" || baseto="$fn"
  12. echo -n "Creating link $linkat$baseto to point to $linkto"
  13. test "$#" -gt 2 && {
  14. echo -n ' with args "'
  15. printf '%q' "$3"
  16. test "$#" -gt 3 && printf ' %q' "${@:4}"
  17. echo -n '"';
  18. }
  19. echo
  20. test -z "$linkat$fn" && linkat=./
  21. set -x
  22. ln -sT "${@:3}" "$linkto" "$linkat$baseto"