string - Parse command line args to process a list of files in bash? -


i want create script optional inputs parsed similar how this respone explains containing list of files extension. example usage

./myscript.sh -s 25 -q 0.2 *.txt 

and script store 25 s variable, 0.2 q varable, , list of txt files individually processed. have far

#!/bin/bash -f  # set default values qmax=0.2 profilesize=50  while [[ $# > 0 ]] key="$1" case $key in     -q|--max_q)     qmax="$2"     shift # past argument     ;;     -s|--profile_size)     profilesize="$2"     shift # past argument     ;; esac shift # past argument or value done  var in "$@"     if [[ $var == *".txt" ]]             # on real on each file here         echo $qmax $profilesize $var     fi done 

as is, can run default values commenting out while loop. without commenting out, reads through inputs , there none left for loop compare. think best option create list of files in while loop, use in for loop. ideas of how that?

just append *) case stores argument array.

*) files+=("$1") ;; 

and iterate on files instead of $@:

for file in "${files[@]}" ; 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -