-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptimized.sh
More file actions
46 lines (36 loc) · 997 Bytes
/
optimized.sh
File metadata and controls
46 lines (36 loc) · 997 Bytes
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
#!/bin/bash
# Function to create files in a loop
create_files() {
local prefix="$1"
local extension="$2"
local path="$3"
local start="$4"
local end="$5"
# Validate path
if [ ! -d "$path" ]; then
echo "Error: The path '$path' does not exist."
exit 1
fi
# Create files in a loop
for ((i = start; i <= end; i++)); do
local formatted_index=$(printf "%02d" "$i") # Format as two digits, e.g., 01, 02
local file_name="${prefix}${formatted_index}.${extension}"
local full_path="${path}/${file_name}"
# Create the file
touch "$full_path"
echo "Created: $full_path"
done
}
# Main script
echo "Enter file prefix (e.g., 'ex'): "
read prefix
echo "Enter file extension (e.g., 'c'): "
read extension
echo "Enter path location (e.g., '/home/user/projects'): "
read path
echo "Enter starting number: "
read start
echo "Enter ending number: "
read end
# Call the function with user inputs
create_files "$prefix" "$extension" "$path" "$start" "$end"