-
Notifications
You must be signed in to change notification settings - Fork 0
/
creat_num_files.sh
executable file
·54 lines (49 loc) · 1.02 KB
/
creat_num_files.sh
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
46
47
48
49
50
51
52
53
54
#!/bin/bash
dir=$1
filename=$2
file_regex=$filename[0-9]*$
if [ -d $dir ]
then
echo
echo "$dir DIRECTORY FOUND"
latest=$(ls -v "$dir"|grep "$file_regex"|tail -1)
# check if no filename file exists
if [ -z "$latest" ]
then
echo "No $filename file found."
echo "CREATING ONE ..."
touch "$dir"/$filename
if [ $? -eq 0 ]
then
echo "$filename file created successfully!"
else
echo "An error occured trying to create $filename file"
fi
else
# filename file exist, create next one
echo
echo "$filename file type found"
echo "Latest is $latest"
echo "CREATING NEXT ..."
echo
./number_files.sh "${dir}/${latest}"
fi
else
echo "$dir DIRECTORY NOT FOUND"
echo "Usage: $0 dir_path filename"
echo "Exiting ..."
exit 1
fi
exit 0
#for file in "$dir"/*; do
#
# filename=$(basename "$file")
#
# if [[ "$filename" =~ $file_regex ]]
# then
#
# echo "id_rsa file type found"
# ./number_files.sh "$file"
# exit 0
# fi
# done