3

私は、ファイル名を引数として渡すことができるスクリプトを書いています。それは、特定のファイル拡張子である場合にのみ実行されます。

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

助けてくれてありがとう。

4

1 に答える 1

0

次のコードを試してください。

shopt -s nocasematch

if [[ $1 == *flac ]]; then
    echo "ok"
fi

これは大文字と小文字を区別しません。

編集

$ LANG=C help shopt
shopt: shopt [-pqsu] [-o] [optname ...]
    Set and unset shell options.

    Change the setting of each shell option OPTNAME.  Without any option
    arguments, list all shell options with an indication of whether or not each
    is set.

    Options:
      -o        restrict OPTNAMEs to those defined for use with `set -o'
      -p        print each shell option with an indication of its status
      -q        suppress output
      -s        enable (set) each OPTNAME
      -u        disable (unset) each OPTNAME

    Exit Status:
    Returns success if OPTNAME is enabled; fails if an invalid option is
    given or OPTNAME is disabled.

シェルで単独で実行する場合はshopt、利用可能なすべてのオプションが表示されます。

$ shopt
autocd          on
cdable_vars     on
cdspell         off
checkhash       off
checkjobs       off
checkwinsize    off
cmdhist         on
compat31        off
compat32        off
compat40        off
compat41        off
direxpand       off
dirspell        off
dotglob         on
execfail        off
expand_aliases  on
extdebug        off
extglob         on
extquote        on
failglob        off
force_fignore   on
globstar        on
gnu_errfmt      off
histappend      on
histreedit      off
histverify      off
hostcomplete    off
huponexit       off
interactive_comments    on
lastpipe        off
lithist         off
login_shell     off
mailwarn        off
no_empty_cmd_completion off
nocaseglob      off
nocasematch     off
nullglob        off
progcomp        on
promptvars      on
restricted_shell        off
shift_verbose   off
sourcepath      on
xpg_echo        off

これらすべてのオプションが何をするかを知るには:

man bash | less +/'^SHELL BUILTIN COMMANDS'

次に、このセクション内から`shoptを検索します。

于 2012-10-09T12:15:28.377 に答える