-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkopiuj
41 lines (35 loc) · 822 Bytes
/
kopiuj
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
#!/bin/bash
#Autor: Szymon Szymczewski
#Data: 5.11.2021
#Projekt 1
# Sprawdzanie braku argumentow
if [ $# -eq 0 ]; then
echo "No arguments"
echo "Correct way: kopiuj ../fold_doc plik1 plik2"
exit 1
fi
dir="$1"
# Sprawdzanie dostepu
if [ ! -x $dir ]; then
echo "No permissions"
fi
# Jezeli katalog docelowy nie istnieje to tworzymy go, nie zglaszamy bledu
if [ ! -d $dir ]; then
echo "Creating new folder - $dir"
mkdir $dir
fi
# Zaczynamy od drugiego argumentu
for file in "${@:2}"
do
# Sprawdzanie czy istnieja pliki z argumentow
if [[ ! -f "$file" && ! -d "$file" ]]; then
echo "File ($file) doesnt exist"
fi
# Kopiowanie pliku/folderu do folderu docelowego
if [ -f $file ]; then
cp $file $dir
mv $dir/$file $dir/$file.$USER
elif [ -d $file ]; then
tar cf $dir/$file.$USER.tar $file
fi
done