我正在尝试让所有 MP3 都注册 BPM。我确实找到了可以注册的软件,通过这个超级用户问题。
我安装了陳文婧,vorbis-tools flac python-mutagen
并从名为 Super User 的问题中复制了 bash 脚本(见下文)。现在,问题是这个脚本给了我两个错误:
/home/jeroen/bpmtagging.sh: line 67: warning: here-document at line 4 delimited by end-of-file (wanted
帮助')`/home/jeroen/bpmtagging.sh: line 68: syntax error: unexpected end of file
这是脚本的最后两行。我认为该脚本对 OP 有用,但现在在 Ubuntu 12.04 上不再有效。
我是 Bash 脚本的新手,我尝试查找错误,但无济于事。如能得到任何帮助,我将不胜感激。
#!/bin/bash
function display_help() {
cat <<-HELP
Recursive BPM-writer for multicore CPUs.
It analyzes BPMs of every media file and writes a correct tag there.
Usage: $(basename "$0") path [...]
HELP
exit 0
}
[ $# -lt 1 ] && display_help
#=== Requirements
requires="bpmcount mid3v2 vorbiscomment metaflac"
which $requires > /dev/null || { echo "E: These binaries are required: $requires" >&2 ; exit 1; }
#=== Functions
function bpm_read(){
local file="$1"
local ext="${file##*.}"
declare -l ext
# Detect
{ case "$ext" in
'mp3') mid3v2 -l "$file" ;;
'ogg') vorbiscomment -l "$file" ;;
'flac') metaflac --export-tags-to=- "$file" ;;
esac ; } | fgrep 'BPM=' | cut -d'=' -f2
}
function bpm_write(){
local file="$1"
local bpm="${2%%.*}"
local ext="${file##*.}"
declare -l ext
echo "BPM=$bpm @$file"
# Write
case "$ext" in
'mp3') mid3v2 --TBPM "$bpm" "$file" ;;
'ogg') vorbiscomment -a -t "BPM=$bpm" "$file" ;;
'flac') metaflac --set-tag="BPM=$bpm" "$file"
mid3v2 --TBPM "$bpm" "$file" # Need to store to ID3 as well :(
;;
esac
}
#=== Process
function oneThread(){
local file="$1"
#=== Check whether there's an existing BPM
local bpm=$(bpm_read "$file")
[ "$bpm" != '' ] && return 0 # there's a nonempty BPM tag
#=== Detect a new BPM
# Detect a new bpm
local bpm=$(bpmcount "$file" | grep '^[0-9]' | cut -f1)
[ "$bpm" == '' ] && { echo "W: Invalid BPM '$bpm' detected @ $file" >&2 ; return 0 ; } # problems
# Write it
bpm_write "$file" "${bpm%%.*}" >/dev/null
}
NUMCPU="$(grep ^processor /proc/cpuinfo | wc -l)"
find $@ -type f -regextype posix-awk -iregex '.*\.(mp3|ogg|flac)' \
| while read file ; do
[ `jobs -p | wc -l` -ge $NUMCPU ] && wait
echo "$file"
oneThread "$file" &
done
答案1
该脚本包含定界符,即<<-HELP
。它允许您在两个标识符之间包含文字字符串。此标识符在 之后指定<<
,并且它是HELP
。
在您的脚本中,有一个特殊的语法元素,其与标识符之间有一个。即使标识符以制表-
符<<
缩进,它也能识别标识符,因此您可以这样写:
cat <<-HELP
some indented text
___HELP
这里,___
应该是一个制表符。现在,就你的情况而言,它可能缩进多个空格,这就是为什么找不到 heredoc 的结尾。
对此有两种解决方案:
- 将缩进从空格改为制表符。
- 将标识符移动
HELP
到行首。
如果您使用具有正确语法突出显示的编辑器(或显示空格而不是制表符的编辑器),您应该会看到此错误: