我正在编写一个脚本,该脚本采用## ARTIST - TRACK.flac格式的flac文件,并从文件名和标签中适当地提取信息。我也有一些手动输入其他信息的标志。问题是轨道名称没有被正确标记。似乎它停在第一个白色空间,不管我的引用技术如何,然后抛出一堆其他的东西。你注意到我在标记之前回显了trackname变量,只是为了确保变量是正确的,但是标记仍然是关闭的。感谢您提前获得帮助(以及任何其他指示)!
#!/bin/bash
#
# A flac tagging script
#
while getopts :l:y:s:h opt ;
do
case $opt in
l) ALBUM="--set-tag=ALBUM=${OPTARG}" ;;
y) YEAR="--set-tag=YEAR=${OPTARG}";;
s) SOURCE="--set-tag=SOURCE=${OPTARG}" ;;
h) echo >&2 "tags flac files in folder with arguments: -r [artist] -l [album] -y [year] -s [source (cdr, promot, etc)]" ;;
esac
done
shift $((OPTIND-1))
if [ "$1" ]
then
for file
do
if [ -e "$file" ]
then
echo >&2 "Tagging file: "$file""
filename=$(basename "$file")
extension="${filename##*.}"
filename="${filename%.*}"
TRACKNAME="${filename##*- }"
trackartist="${filename% -*}"
TRACKNUMBER="${trackartist% *}"
ARTIST="${trackartist##* }"
echo >&2 "$TRACKNAME"
metaflac \
--set-tag=ARTIST=$ARTIST\
--set-tag=TITLE=$TRACKNAME \
--set-tag=TRACKNUMBER="$TRACKNUMBER" "$ALBUM" "$YEAR" "$SOURCE"\
"$file"
else
echo >&2 "No such file: "$1""
exit 1
fi
done
else
echo >&2 "Usage: "$(basename "$0")" INPUTFILE [...]"
exit 1
fi
答案 0 :(得分:0)
快速重写
#!/bin/bash
tags=()
while getopts :l:y:s:h opt; do
case $opt in
l) tags+=( --set-tag=ALBUM="$OPTARG" ) ;;
y) tags+=( --set-tag=YEAR="$OPTARG" ) ;;
s) tags+=( --set-tag=SOURCE="$OPTARG" ) ;;
h) echo >&2 "tags flac files in folder with arguments: -l [album] -y [year] -s [source (cdr, promot, etc)]" ;;
esac
done
shift $((OPTIND-1))
if [ $# -eq 0 ]; then
echo >&2 "Usage: $(basename "$0") [options] INPUTFILE [...]"
exit 1
fi
for file; do
if ! [ -e "$file" ]; then
echo >&2 "Error: No such file: $1"
continue
fi
if ! [[ $(basename "$file") =~ ([0-9]+)" "(.+)" - "(.+)".flac"$ ]]; then
echo >&2 "Error: can't parse filename: $file"
continue
fi
echo >&2 "Tagging file: $file"
metaflac "${tags[@]}" \
--set-tag=ARTIST="${BASH_REMATCH[2]}" \
--set-tag=TITLE="${BASH_REMATCH[3]}" \
--set-tag=TRACKNUMBER="${BASH_REMATCH[1]}" \
"$file"
done
注意:
PATH=/my/file
,然后想知道为什么你的脚本坏了