Я прохожу курс “от 0 до Linux админа” здесь и столкнулся с проблемой:
Я написал скрипт для конвертации директории JPEG-файлов в один PDF-документ, и хотел бы, чтобы кто-то его улучшил или исправил. Вот код:
#!/bin/bash
# --- Colors for terminal messages ---
RED='\033[0;31m' # Red
GREEN='\033[0;32m' # Green
YELLOW='\033[0;33m' # Yellow
BLUE='\033[0;34m' # Blue
NC='\033[0m' # Reset color
# --- Trap setting for cleaning temporary files on exit/error ---
trap cleanup EXIT
trap control_c INT TERM
# --- Function to display script information ---
Info_data() {
...
}
# --- Global variable for fast mode ---
FAST_MODE=false
# --- Global variable for temporary directory ---
TEMP_DIR=""
# --- Function to clean up the temporary directory ---
cleanup() {
...
}
control_c () {
...
}
make_temp_dir () {
...
}
# --- Function to validate arguments and dependencies ---
validate_arguments() {
...
}
# --- Initial argument parsing and help check ---
if [ "$#" -eq 0 ] || [ "$1" == "-help" ] || [ "$1" == "-h" ]; then
Info_data
exit 0
fi
# Check if fast mode is active
...
# Determine output PDF filename and list of JPG files based on the first argument.
...
validate_arguments "$output_pdf" "${input_jpgs[@]}"
# --- Call the print mode selection function ---
select_print_mode
# --- Call the temporary directory creation function ---
make_temp_dir
# --- Processing each JPG file ---
for jpg_file in "${input_jpgs[@]}"; do
...
done
echo "✅ Operation completed successfully. New PDF file: $output_pdf"
У меня есть некоторые сомнения по поводу обработки ошибок и улучшения кода. Можете ли вы помочь с оптимизацией или исправлениями? Спасибо!