This shell command converts all .avi to .mp4 as per this answer by @llogan
Can someone explain how ${i%.*} works? In particular, what does % do?
for i in *.avi; do ffmpeg -i "$i" "${i%.*}.mp4"; done
This shell command converts all .avi to .mp4 as per this answer by @llogan
Can someone explain how ${i%.*} works? In particular, what does % do?
for i in *.avi; do ffmpeg -i "$i" "${i%.*}.mp4"; done
From BashGuide/Parameters/Parameter Expansion:
${parameter%pattern}
Thepattern
is matched against the end ofparameter
. The result is the expanded value ofparameter
with the shortest match deleted.
From How do I do string manipulations in bash?:
The
%
means "remove the shortest possible match from the end of the variable's contents"
In other words, if the expanded value of parameter
(i
in your case) is myvideo.avi
, then %.*
will result in myvideo
. This is so the output file does not end up being named myvideo.avi.mp4
, and instead is named myvideo.mp4
.