renamer.sh 742 B

12345678910111213141516171819202122232425262728
  1. #!/bin/bash
  2. # Check if $DIST_DIR and $FILE_SUFFIX are set
  3. if [ -z "$FILE_SUFFIX" ] || [ -z "$DIST_FILE" ]; then
  4. echo "Error: \$DIST_DIR and \$FILE_SUFFIX must be set"
  5. exit 1
  6. fi
  7. # $DIST_FILE
  8. DIST_FILE=$(echo "$DIST_FILE" | head -n 1)
  9. DIST_DIR=$(dirname "$DIST_FILE")
  10. # Loop through files in $DIST_DIR
  11. for file in "$DIST_DIR"/*; do
  12. # Check if the item is a regular file
  13. if [ -f "$file" ]; then
  14. # Extract the filename and extension
  15. filename=$(basename "$file")
  16. extension="${filename##*.}"
  17. name="${filename%.*}"
  18. # Construct the new filename
  19. new_filename="${name}-${FILE_SUFFIX}.${extension}"
  20. # Rename the file
  21. mv "$file" "$DIST_DIR/${new_filename}"
  22. fi
  23. done