find . -type f -name '*.json2' -exec sh -c '
for pathname; do
[ -e "$pathname.ml" ] && continue
curl -X POST -H "Content-Type: application/json" -d @"$pathname" https://api.myweb.com/api >"$pathname.ml"
done' sh {} +
This would find all regular files whose filenames match the pattern *.json2
in or below the current directory. For batches of these files, a short shell script is executed. This script tests, for each pathname given to it by find
, whether there's a .ml
file corresponding to the pathname. If there is not, your curl
command is executed.
This could be simplified into the following if all files are located in the current directory only:
for pathname in ./*.json2; do
[ -e "$pathname.ml" ] && continue
curl -X POST -H "Content-Type: application/json" -d @"$pathname" https://api.myweb.com/api >"$pathname.ml"
done
Note that this is essentially exactly the same loop as in the script called by find
. The only difference is that in the first example, find
act as a pathname generator for the loop, while in the shorter example, the pathnames are generated using a globbing pattern (and only from the current directory).
Related:
$0
. – Kusalananda Aug 29 '18 at 10:17