lab1
.pdfСодержимое скрипта
#!/bin/bash
DIR="./arc"
if [ ! -d $DIR ]; then mkdir $DIR
fi
for x in "$@" do
if [ ! -e "$x" ];then
echo "$x wasn't copied because it doesn't exist" elif [ "$x" -nt "$DIR/$x" ];then
cp $x $DIR && echo "$x copied" else
echo "$x wasn't copied because there's newer copy in the $DIR folder"
fi done
Проверка работы
[dtr@snail ~]$ touch 1 2 4 [dtr@snail ~]$ ls -d arc
ls: невозможно получить доступ к arc: Нет такого файла или каталога [dtr@snail ~]$ ./smartcopy.sh 1 2 4
1 copied
2copied 4 copied
[dtr@snail ~]$ touch 1 [dtr@snail ~]$ ls -l [1-4]
-rw-r--r-- 1 dtr users 0 2011-10-13 20:31 1 -rw-r--r-- 1 dtr users 0 2011-10-13 20:30 2 -rw-r--r-- 1 dtr users 0 2011-10-13 20:30 4 [dtr@snail ~]$ ls -l arc/*
-rw-r--r-- 1 dtr users 0 2011-10-13 20:30 arc/1 -rw-r--r-- 1 dtr users 0 2011-10-13 20:30 arc/2 -rw-r--r-- 1 dtr users 0 2011-10-13 20:30 arc/4 [dtr@snail ~]$ ./smartcopy.sh 1 2 3 4
1 copied
2wasn't copied because there's newer copy in the ./arc folder 3 wasn't copied because it doesn't exist
4 wasn't copied because there's newer copy in the ./arc folder