Validate script's argument by file extension? Validate script's argument by file extension? shell shell

Validate script's argument by file extension?


Try the following code:

shopt -s nocasematchif [[ $1 == *flac ]]; then    echo "ok"fi

This is case insensitive.

EDIT

$ LANG=C help shoptshopt: 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.

If you run shopt alone in a shell, you will see al options available :

$ shoptautocd          oncdable_vars     oncdspell         offcheckhash       offcheckjobs       offcheckwinsize    offcmdhist         oncompat31        offcompat32        offcompat40        offcompat41        offdirexpand       offdirspell        offdotglob         onexecfail        offexpand_aliases  onextdebug        offextglob         onextquote        onfailglob        offforce_fignore   onglobstar        ongnu_errfmt      offhistappend      onhistreedit      offhistverify      offhostcomplete    offhuponexit       offinteractive_comments    onlastpipe        offlithist         offlogin_shell     offmailwarn        offno_empty_cmd_completion offnocaseglob      offnocasematch     offnullglob        offprogcomp        onpromptvars      onrestricted_shell        offshift_verbose   offsourcepath      onxpg_echo        off

To know what does all these options :

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

then search `shopt from within this section.