【发布时间】:2018-02-09 19:29:45
【问题描述】:
我制作了一个简短的 bash 程序来下载播客并仅检索最后 20 秒。
奇怪的是,每隔一个迭代就下载一次失败。函数trim_nsec 似乎有问题,因为当我在循环中摆脱它时,其余的都可以正常工作。
编辑:添加双引号,这并不能解决问题
<!-- language: lang-bash -->
#!/bin/bash
# Get podcast list
wget -O feed http://www.rtl.fr/podcast/on-n-est-pas-forcement-d-accord.xml
function trim_nsec () {
# arguments : 1 : mp3file - 2 : duration - 3 : outputfile
duration=$(ffprobe -i "${1}" -show_entries format=duration -v quiet -of csv="p=0")
nth_second=$(echo "${duration} - ${2}"|bc)
ffmpeg -i "${1}" -ss "${nth_second}" "${3}"
}
cpt=1
# let's work only on the 4th first files
grep -Po 'http[^<]*.mp3' feed|grep admedia| head -n 4 > list
cat list | while read i
do
year=$(echo "$i" | cut -d"/" -f6)
day=$(echo "$i" | cut -d"/" -f7)
fullname=$(echo "$i" | awk -F"/" '{print $NF}')
fullnameend=$(echo "$fullname" |sed -e 's/\.mp3$/_end\.mp3/')
new_name=$(echo "$year"_"$day"_"$fullnameend")
# let's download
wget -O "$fullname" "$i"
# let's trim last 20 sec
trim_nsec "$fullname" 20 "$new_name"
echo "$cpt file processed"
#delete orig. file :
rm "$fullname"
((cpt++))
done
有什么想法吗?
【问题讨论】:
-
使用双引号,很可能出现意外通配问题。见:shellcheck.net
-
嗯。即使 shellcheck 要求使用 alla 双引号,它仍然会在所有其他迭代中失败。
-
请edit您的问题反映双引号的添加