#!/bin/bash # Default values VERBOSE=false INPUT_FILE="" OUTPUT_DIR="./output" # Function to display usage information usage() { echo "Usage: $0 [-v] [-i ] [-o ]" echo " -v: Enable verbose output" echo " -i : Specify an input file (required)" echo " -o : Specify an output directory (default: ./output)" echo " -h: Display this help message" exit 1 } # Parse command line options while getopts "vi:o:h" opt; do case "${opt}" in v) VERBOSE=true ;; i) INPUT_FILE="${OPTARG}" ;; o) OUTPUT_DIR="${OPTARG}" ;; h) usage ;; *) echo "Invalid option: -${OPTARG}" >&2 usage ;; esac done shift $((OPTIND-1)) # Remove parsed options from argument list # Validate required arguments if [ -z "${INPUT_FILE}" ]; then echo "Error: Input file must be specified using -i." >&2 usage fi # Create output directory if it doesn't exist if [ ! -d "${OUTPUT_DIR}" ]; then mkdir -p "${OUTPUT_DIR}" [ "${VERBOSE}" = true ] && echo "Created output directory: ${OUTPUT_DIR}" fi # Main script logic [ "${VERBOSE}" = true ] && echo "Verbose mode enabled." echo "Processing file: ${INPUT_FILE}" echo "Output directory: ${OUTPUT_DIR}" # Example of what the script might do # cp "${INPUT_FILE}" "${OUTPUT_DIR}/$(basename ${INPUT_FILE})" # echo "File copied to ${OUTPUT_DIR}/$(basename ${INPUT_FILE})"