File: clink.sh

package info (click to toggle)
clig 1.1.3-4
  • links: PTS
  • area: main
  • in suites: potato
  • size: 328 kB
  • ctags: 72
  • sloc: tcl: 1,459; ansic: 253; makefile: 109; sh: 60; csh: 52
file content (36 lines) | stat: -rwxr-xr-x 895 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/sh -e
#
# usage: clink.csh dstDir file [file ...]
#
# For each file create a soft link in dstDir pointing to it. If file
# exists already in dstDir as a soft link, the link is replaced. If
# file already exist as anything else, this is silently ignored.
# If dstDir does not exist, this is silently ignored
#set -x

if [ $# -lt 2 ]; then exit 1 ; fi

dstDir=$1 ; shift

if [ ! -d $dstDir ]; then
  echo "warning: no soft link(s) created in $dstDir (dir does not exist)"
  exit 0
fi


for file do
  x=`basename $file`

  ## We feel free to remove soft links. Too bad that csh cannot test for
  ## soft links. 
  if [ -h $dstDir/$x ]; then rm $dstDir/$x ; fi

  ## However we don't touch real files
  if ln -s $file $dstDir 2> /dev/null ; then
    echo "creating soft link $dstDir/$x --> $file"
  else
    echo "warning: didn't create soft link $dstDir/$x"
  fi
done
exit 0
##### end #####