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

Posted by Corbin Tarrant on Stack Overflow See other posts from Stack Overflow or by Corbin Tarrant
Published on 2010-04-05T23:03:33Z Indexed on 2010/04/05 23:13 UTC
Read the original article Hit count: 318

Filed under:
|
#!/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 Error, Please provide at least one type, ex: sizeofTypes {filetype1} {filetype2}"
  exit 0
fi

#set first filetype
types="-name *."$1

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

echo "TYPES="$types

find . -name '*.'$1 | xargs du -ch *.$1 | grep total

The problem I'm having is right here:

 #loop through additional filetypes and append
    num=1
    while [ $num -lt $# ]
    do
      (( num++ ))
      types=$types' -o -name *.'>>$$num<<
    done

I simply want to iterate over all the arguments not including the first one, should be easy enough, but I'm having a difficult time figuring out how to make this work

© Stack Overflow or respective owner

Related posts about shell-scripting

Related posts about bash