私は、ファイル名を引数として渡すことができるスクリプトを書いています。それは、特定のファイル拡張子である場合にのみ実行されます。
flac2mp3 "01 Song.flac"
また
flac2mp3 "01 Song.FLAC"
flacをmp3に変換する方法を示すスクリプトがたくさんあることは知っていますが、これは私のスクリプトであり、この方法を使用してスクリプトを作成する方法を学びたいと思います。
それは私が議論を学ぶことができるようにするためであり、私が1つの個別のファイルだけを変換したいと思うときのために。(複数のファイルの場合、スクリプト内に* .flacを使用してforループを作成しました)
$1引数に*。[Ff][Ll][Aa][Cc]が含まれているかどうかを確認する方法を知りたいだけです。
これが私がこれまでインターネットから一緒に考え出したものです(私は恥ずかしいほど間違っていることを知っていますが、私が何をしようとしていたかを示したかったです):
#!/bin/bash
#flac2mp3
if [ -z $1 ] && [[$1 !=~ *.[Ff][Ll][Aa][Cc]]];then echo "Give FLAC File Name"; exit 0;fi
OUTF=${1%.flac}.mp3
ARTIST=$(metaflac "$1" --show-tag=ARTIST | sed s/.*=//g)
TITLE=$(metaflac "$1" --show-tag=TITLE | sed s/.*=//g)
ALBUM=$(metaflac "$1" --show-tag=ALBUM | sed s/.*=//g)
GENRE=$(metaflac "$1" --show-tag=GENRE | sed s/.*=//g)
TRACKNUMBER=$(metaflac "$1" --show-tag=TRACKNUMBER | sed s/.*=//g)
DATE=$(metaflac "$1" --show-tag=DATE | sed s/.*=//g)
flac -c -d "$1" | lame -m j -q 0 --vbr-new -V 0 -s 44.1 - "$OUTF"
id3 -t "$TITLE" -T "${TRACKNUMBER:-0}" -a "$ARTIST" -A "$ALBUM" -y "$DATE" -g "${GENRE:-12}" "$OUTF"
done
助けてくれてありがとう。