Skip to content

Instantly share code, notes, and snippets.

@jhanschoo
Last active December 24, 2015 01:29
Show Gist options
  • Save jhanschoo/6723841 to your computer and use it in GitHub Desktop.
Save jhanschoo/6723841 to your computer and use it in GitHub Desktop.
#!/bin/bash
for FILENAME in "$@"
do
export FILENAME
NEWNAME="$(exiv2 $FILENAME | grep "Image timestamp" | cut -d ' ' -f 4,5 | sed 's/\(.*\) \(.*\)/\1T\2.jpg/')"
# don't forget to quote
if [ "$NEWNAME" != "" ] # equivalent to [ -n "$NEWNAME" ]
then
mv "$FILENAME" "$NEWNAME"
elif [ ! -e "$FILENAME" ] # file does not exist
then
echo "$0: $FILENAME: No such file" 1>&2
else
echo "$0: $FILENAME: No EXIF timestamp" 1>&2
fi
done
#!/bin/bash
while getopts "e:" opt "$@"
do
case $opt in
e)
export EXTENSION="$OPTARG"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
esac
done
for FILENAME in "${@:$OPTIND}"
do
export FILENAME
# this line is changed
NEWNAME="$(exiv2 $FILENAME | grep "Image timestamp" | cut -d ' ' -f 4,5 | sed 's/\(.*\) \(.*\)/\1T\2'"$EXTENSION"'/')"
# don't forget to quote
if [ "$NEWNAME" != "" ] # equivalent to [ -n "$NEWNAME" ]
then
mv "$FILENAME" "$NEWNAME"
elif [ ! -e "$FILENAME" ] # file does not exist
then
echo "$0: $FILENAME: No such file" >&2
else
echo "$0: $FILENAME: No EXIF timestamp" >&2
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment