Context: zsh Catalina MacOS:
The executable script BatesStamp engages imagemagick to stamp a number to a jpg file:
# BatesStamp: OVERWRITES and stamps ONE file with COUNTER (upper left corner)
# usage ./BatesStamp COUNTER PATH_FILE
# to be used with find & -exec: https://unix.stackexchange.com/a/96239/182280
COUNTER=$1 # 1st argument = number to be stamped upon .jpg file
PATH_FILE=$2 # 2nd argument = /path_to_file/Filename.jpg
convert $PATH_FILE -auto-orient -gravity northWest -font "Arial-Bold-Italic" -pointsize 175
-fill red -annotate +30+30 "$COUNTER" $PATH_FILE;
((COUNTER++)) #https://stackoverflow.com/a/21035146/4953146
echo "watermarked i= $COUNTER $PATH_FILE"
The goal is to stamp all .jpg files in directory tree with a unique number. I believe $COUNTER must be incremented every time it is called: this ensure each file is stamped with a unique number. The strategy is to traverse all subdirectories with find
to identify .jpg files and BatesStamp each .jpg file with $COUNTER++.
This script goBatesStamp.sh
traverses subdirectories to exec each .jpg files to be processed by BatesStamp
# goBastesStamp.sh
cd /Users/user/Desktop/AITH_USB_Hope_Submitted_MyCloud/PhotoGraphs_Work/A_Building_NoBulkhead. # navigate to top level directory
COUNTER=100 # initialize COUNTER
find /Users/user/Desktop/AITH_USB_Hope_Submitted_MyCloud/PhotoGraphs_Work/A_Building_NoBulkhead -iname "*.jpg" -exec ./BatesStamp $((COUNTER+=1)) {} \;
The problem is in the line beginning with the find
command. Specifically, the COUNTER does not increment.
Test show that .jpg files are stamped with the number 100 It seams that the $((COUNTER++)) is the problem. What is the proper syntax to increment the COUNTER by one and feed the incremented COUNTER into ./BatesStamp?
#! /bin/zsh -
however, that is whole new discussion, but may be helpful for readers. TL\DR: ensure#! /bin/zsh -
is on line 1 with nothing before it. – gatorback Nov 20 '21 at 15:39#!
have to be the first two bytes of the file. That is the special signal to the system (not the shell) that the file is a script. As far as the shell is concerned, that line is just a comment as it starts with#
– Stéphane Chazelas Nov 20 '21 at 15:57