3 # Creates a symbolic link for file $1 in dirname of $2 with name of basenmae
6 # `./link.sh example ~/.examplerc` creates a symbolic link to example
7 # (wherever it is located) in ~/ named .examplerc.
10 # Get all necessary paths.
13 source=`echo -n "$pwd/$1" | sed "s|$base/||"`
14 target=`basename "$2"`
16 # Go to the directory where the link is going to be created.
19 # Abort if the target file exists and is no symbolic link. Prevents
20 # overwriting real files.
21 if [ -e "$target" -a ! -h "$target" ]; then
22 echo "target '$target' exists already and is no symbolic link!" >&2
26 # Make sure the source exists.
27 if [ ! -e "$source" ]; then
28 echo "source '$source' doesn't exist!" >&2
32 # Create the new symbolic link; remove the old one if necessary.
34 ln -s "$source" "$target"