Skip to content

Instantly share code, notes, and snippets.

@lee2sman
Created June 30, 2021 03:35
Show Gist options
  • Save lee2sman/17bd6fa484c85c8952e7180f481386f7 to your computer and use it in GitHub Desktop.
Save lee2sman/17bd6fa484c85c8952e7180f481386f7 to your computer and use it in GitHub Desktop.
#!/usr/bin/bash
## A hack to export all image files to a json list
# find name of last file in directory
declare -a files
files=(img/*)
pos=$(( ${#files[*]} - 1 ))
last=${files[$pos]}
#overwrite file if already there
echo "{" > img-list.json
echo ' "name": [' >> img-list.json
for FILE in "${files[@]}"
do
if [[ $FILE == $last ]]
then
echo " "\"$FILE\" >> img-list.json
break
else
echo " "\"$FILE\", >> img-list.json
fi
done
echo " ]" >> img-list.json
echo "}" >> img-list.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment