I have the following JPEG files :
$ ls -l -rw-r--r-- 1 user group 384065 janv. 21 12:10 CamScanner 01-10-2022 14.54.jpg -rw-r--r-- 1 user group 200892 janv. 10 14:55 CamScanner 01-10-2022 14.55.jpg -rw-r--r-- 1 user group 283821 janv. 21 12:10 CamScanner 01-10-2022 14.56.jpg I use $ img2pdf to transform each image into a PDF file. To do that :
$ find . -type f -name "*.jpg" -exec img2pdf "{}" --output $(basename {} .jpg).pdf \; Result :
$ ls -l *.pdf -rw-r--r-- 1 user group 385060 janv. 21 13:06 CamScanner 01-10-2022 14.54.jpg.pdf -rw-r--r-- 1 user group 201887 janv. 21 13:06 CamScanner 01-10-2022 14.55.jpg.pdf -rw-r--r-- 1 user group 284816 janv. 21 13:06 CamScanner 01-10-2022 14.56.jpg.pdf How can I remove the .jpg part of the PDF filenames ? I.e., I want CamScanner 01-10-2022 14.54.pdf and not CamScanner 01-10-2022 14.54.jpg.pdf.
Used alone, $ basename filename .extension prints the filename without the extension, e.g. :
$ basename CamScanner\ 01-10-2022\ 14.54.jpg .jpg CamScanner 01-10-2022 14.54 But it seems that syntax doesn't work in my $ find command. Any idea why ?
Note : if you replace $ img2pdf by $ echo it's the same, $ basename doesn't get rid of the .jpg part :
$ find . -type f -name "*.jpg" -exec echo $(basename {} .jpg).pdf \; ./CamScanner 01-10-2022 14.56.jpg.pdf ./CamScanner 01-10-2022 14.55.jpg.pdf ./CamScanner 01-10-2022 14.54.jpg.pdf
$()is shell expansion, that's done before find even gets called. At that point, basename tries to work on the literal{}.