~johanvandegriff/unix-shell-programming-revised-edition-programs

unix-shell-programming-revised-edition-programs/cp -rw-r--r-- 627 bytes
fc214385Johan Vandegriff added other old scripts, some newer ones too 1 year, 8 months ago
                                                                                
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
37
38
39
40
41
42
43
44
45
#!/bin/sh

numargs=$#
filelist=
copylist=

while [ "$#" -gt 1 ]
do
  filelist="$filelist $1"
  shift
done

to="$1"

if [ "$numargs" -gt 2 ]
then
  name=`basename $0`
  echo "Usage: $name file1 file2"
  echo "       $name file(s) dir"
  exit 1
fi
for from in filelist
do
  if [ -d "$to" ]
  then
    tofile="$to/`basname $from`"
  else
    tofile="$to"
  fi
  if [ -f "$tofile" ]
  then
    echo -n "$tofile already exists; overwrite it(yes/no)?"
    read answer
  else
    answer="yes"
  fi
  if [ "$answer" = "yes" ]
  then
    copylist="$copylist $from"
  fi
  if [ -n "$copylist" ]
  then
    cp "$copylist" "$to"
  fi
done