Can someone explain the inner working of the symbols at the end of this bash: “_ {} \;”

后端 未结 1 1365
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-13 16:14

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

1条回答
  •  遥遥无期
    2021-01-13 16:37

    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.

    0 讨论(0)
提交回复
热议问题