fix: use null-safe while loop for filename handling in scripts
Security Scan and Upload / Security & DefectDojo Upload (pull_request) Successful in 49s

This commit is contained in:
2026-03-10 10:37:33 -07:00
committed by Naomi Carrigan
parent ba54dfc76b
commit 6947821eaf
2 changed files with 10 additions and 10 deletions
+4 -4
View File
@@ -1,4 +1,4 @@
IFS=$'\n'
#!/bin/bash
# Initialize an empty string to hold the list of songs in JSON-like format
songs=""
@@ -7,7 +7,7 @@ echo "Found $filecount files."
current=0
# Loop over each file found by find
for file in $(find "/mnt/c/Users/accou/Music" -type f -print0 | tr '\0' '\n'); do
while IFS= read -r -d $'\0' file; do
current=$((current + 1))
echo -ne "Processing $current/$filecount\r"
title=$(mid3v2 -l "$file" | grep "TIT2\|TT2" | cut -d "=" -f 2)
@@ -22,11 +22,11 @@ for file in $(find "/mnt/c/Users/accou/Music" -type f -print0 | tr '\0' '\n'); d
# use jq to add the song to the list
songs="$songs$(jq -n --arg title "$title" --arg artist "$artist" '{title: $title, artist: $artist}'),"
done
done < <(find "/mnt/c/Users/accou/Music" -type f -print0)
# Remove trailing comma and add square brackets to complete the list
songs="[${songs%,}]"
# Write to ./music/songs.json
echo "$songs" > ./music/songs.json
echo -ne "Done!\r"
echo -ne "Done!\r"