add(unitproc:bkmvln):Import symbolic link move script
[BK-2020-03.git] / unitproc / bkmvln
... / ...
CommitLineData
1#!/bin/bash
2#
3# inspired by https://stackoverflow.com/questions/8523159/how-do-i-move-a-relative-symbolic-link#8523293
4# by Christopher Neylan
5
6help() {
7 echo 'usage: mv_ln src_ln dest_dir'
8 echo ' mv_ln --help'
9 echo
10 echo ' Move the symbolic link src_ln into dest_dir while'
11 echo ' keeping it relative'
12 exit 1
13}
14
15[ "$1" == "--help" ] || [ ! -L "$1" ] || [ ! -d "$2" ] && help
16
17set -e # exit on error
18
19orig_link="$1"
20orig_name=$( basename "$orig_link" )
21orig_dest=$( readlink -f "$orig_link" )
22dest_dir="$2"
23
24ln -r -s "$orig_dest" "$dest_dir/$orig_name"
25rm "$orig_link"