How do I use a variable argument number in a bash script?

后端 未结 3 1789
渐次进展
渐次进展 2020-12-31 06:52
#!/bin/bash
# Script to output the total size of requested filetype recursively

# Error out if no file types were provided
if [ $# -lt 1 ]
then 
  echo \"Syntax Err         


        
3条回答
  •  被撕碎了的回忆
    2020-12-31 07:31

    If all you're trying to do is loop over the arguments, try something like this:

    for type in "$@"; do
        types="$types -o -name *.$type"
    done
    

    To get your code working though, try this:

    #loop through additional filetypes and append
    num=1
    while [ $num -le $# ]
    do
        (( num++ ))
        types=$types' -o -name *.'${!num}
    done
    

提交回复
热议问题