[...]
for i in `cat list.txt`
永远不要使用这种语法:
for i in $(command); do ...; done # or
for i in `command`; do ...; done
这种语法逐字读取命令的输出,而不是逐行读取,这通常会产生意想不到的问题(例如,当行包含一些空格以及当您想要读取一行时,例如某个项目)。
总有一个更聪明的解决方案:
command|while read -r; do ...; done # better general case to read command output in a loop
while read -r; do ...; done <<< "$(command)" # alternative to the previous solution
while read -r; do ...; done < <(command) # another alternative to the previous solution
for i in $DIR/*; do ...; done # instead of "for i in $(ls $DIR); do ...; done
for i in {1..10}; do ...; done # instead of "for i in $(seq 1 10); do ...; done
for (( i=1 ; i<=10 ; i++ )); do ...; done # such that the previous command
while read -r; do ...; done < file # instead of "cat file|while read -r; do ...; done"
while read -r || [[ -n $REPLY ]]; do ...; done < file # Same as before but also deal with files that doesn't have EOF.
# dealing with xargs or find -exec sometimes...
# ...
我写了一门课程,其中包含有关此主题和反复出现的错误的更多详细信息,但不幸的是用法语:)
要回答原始问题,您可以使用以下内容:
Convert() {
ffmpeg -i “$1” -vcodec mpe4 -sameq -acodec aac -strict experimental “$1.mp4”
}
Convert_loop(){
while read -r; do
Convert $REPLY
done < $1
}
Convert_loop list.txt