I ran the following command in shell to batch convert .HEIC
files to .JPG
files, the command is successful, however there\'s a part of it I don\'t
There are two things involved in how _ {}
assigns the filename to $1
. First, is how the find
's -exec
works: it runs the following arguments (up to the escaped ;
) as a command, but with {}
replaced with the path to the file it found. Thus, if it finds ./somefile.HEIC
, it'll run the equivalent of the command:
sh -c 'magick convert $1 "${1%.HEIC}.JPG"' _ ./somefile.HEIC
The second part is the sh
command. sh
can do a number of things, but if it's given a -c
option, it takes the immediately following argument (magick convert $1 "${1%.HEIC}.JPG"
) as a command string to parse and run, sort of like a little mini-script. The arguments after that are taken as arguments to that mini-script, starting with $0
. In this case, that means it runs the mini-script with $0
set to _
, and $1
set to "./somefile.HEIC". If more arguments were supplied, they'd be $2
, $3
, etc.