Since i have some video courses in my laptop. I now want to calculate the total time of every course. So i write a simple script with bash.
It succeeds for file/dir without space. But for dir/files with space, it goes wrong. I have tried to set IFS to something else, it doesn't work either. Well, there also some bugs in it.
#!/bin/bash
## Usage: calTime.sh dir
#set -e
getTime(){
message=$($VIDEOTOOL $OPTION $FILE | grep "Duration")
if [ $? -eq 0 ]
then
local time=$(echo $message | cut -d',' -f1 | cut -d' ' -f5)
echo -e $time "\t" $FILE
#second=$(($second + $time))
let second+=$time
fi
} 2>/tmp/error
process(){
if [ -f $FILE ]
then
getTime
elif [ -d $FILE ]
then
cd $FILE
for i in $(ls);
do
local FILE=$i
process
done
fi
}
#################
#### main #######
#################
VIDEOTOOL=/usr/bin/avidemux2_cli
OPTION="--nogui --info --load"
second=0
list=${@-./}
for FILE in $list
do
process
done
echo $second