Bash-Skriptfehler

1364
Desd

Ich versuche, alle meine MP3s für die Registrierung des BPM zu erhalten. Ich habe dafür Software über diese Super User-Frage gefunden .

Ich installierte bpmdj, vorbis-tools flac python-mutagenund kopierte den Bash - Skript aus der genannten Super User Frage (siehe unten). Das Problem ist nun, dass dieses Skript mir zwei Fehler gibt:

  1. /home/jeroen/bpmtagging.sh: line 67: warning: here-document at line 4 delimited by end-of-file (wantedHILFE ")"
  2. /home/jeroen/bpmtagging.sh: line 68: syntax error: unexpected end of file

Dies sind die letzten beiden Zeilen des Skripts. Ich gehe davon aus, dass das Skript für das OP funktionierte, aber es funktioniert jetzt nicht mehr unter Ubuntu 12.04.

Ich bin neu im Bash-Scripting und habe versucht, die Fehler zu finden, aber ohne Erfolg. Jede Hilfe wäre dankbar.

#!/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="$" 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="$" local ext="$" 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" "$" >/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 
2

1 Antwort auf die Frage

2
slhck

The script contains a heredoc, which is <<-HELP. It allows you to include literal strings between two identifiers. This identifier is specified after the <<, and it's HELP.

In the script you have, there's a special syntax element with a - between << and the identifier. It allows the identifier to be recognized even if it's indented by tabs, so you could write:

cat <<-HELP some indented text ___HELP 

Here, ___ would be a tab. Now, in your case, it's probably indented by multiple spaces, which is why the end of the heredoc isn't found.

There are two solutions for this:

  • Change your indentation from spaces to tabs.
  • Move the HELP identifier to the start of the line.

If you use an editor with proper syntax highlighting (or one that shows spaces vs. tabs), you should see this error:

Vielen Dank! Das hat funktioniert. Ich habe die Leerzeichen in eine Registerkarte geändert. Ich bezweifle, dass ich das alleine gefunden hätte. Desd vor 11 Jahren 0
Kein Problem! Meine Antwort wurde mit einem Screenshot eines Editors aktualisiert. Wenn diese Syntax richtig markiert ist, können Sie diese Dinge erkennen! slhck vor 11 Jahren 0