LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-11-2009, 07:04 AM   #1
wonderfullyrich
LQ Newbie
 
Registered: Sep 2009
Location: Kampala
Distribution: Ubuntu
Posts: 10

Rep: Reputation: 0
converting a for loop to an array so zenity can give progress


I've got a script processing a timelapse stills into a movie and I'd like to get zenity to show me the progress of the for loop. I believe the only way to do this is to dump ls listing into an array, then show the progress based on the array. I'm stumbling with converting this for loop into an array. Can anyone throw me a bone?

Code:
#!/bin/sh

imgsize="720x480"
himgsize=resized_to_$imgsize

#create directory if not exist 
echo --------- create directory "$himgsize"
if [ ! -d $himgsize  ] ;then
		mkdir $himgsize
fi

echo --------- processing images

#iterate through selected images, resize, and rename
for file in `ls -C1 --ignore=resized_to_*`
do
name=`echo $file | cut -f1 -d.`
  convert +page -type TrueColor -filter sinc -geometry $imgsize $file $himgsize/$file

done

outputfilename=${PWD##*/}
echo --------- ${outputfilename} images processed 
echo 
echo --------- starting mpg encode


if [ -e ../../${outputfilename}.mpg  ] ;

then
DATE=`date +%Y%m%e-%H%M`
outputfilename=${outputfilename}_$DATE

fi

mencoder mf://$himgsize/*.JPG -mf w=720:h=480:fps=12:type=JPG -of mpeg -mpegopts format=mpeg2:tsaf:muxrate=3600 -o ../../${outputfilename}.mpg -oac lavc -lavcopts acodec=mp2:abitrate=224 -ovc lavc -lavcopts vcodec=mpeg2video:vbitrate=4096:keyint=15:mbd=2

echo --------- ${outputfilename}.mpg has been created
Thanks
Rich
 
Old 09-12-2009, 08:26 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,524
Blog Entries: 27

Rep: Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175Reputation: 1175
This should do the trick
Code:
IFS='
' files=( $(/bin/ls -1 --ignore=resized_to_*) )

for (( i = 0; i < ${#files[*]}; i++ ))
do
   file="${files[$i]}"
   <commands>
done
The $IFS setting is only in effect for one command. The $(<command>) format is more robust than `<command>`. Using /bin/ls ensures the command itself is used rather than an alias. I think the -C option of ls is redundant when specified with the -1 option.
 
Old 03-01-2012, 08:58 AM   #3
korobass
LQ Newbie
 
Registered: Mar 2012
Posts: 1

Rep: Reputation: Disabled
Simple way to show progress every loop in bash

Code:
LOOPCOUNT=1
NUMFILES=`echo $FILES | wc -w`

(for FILE in $FILES; do
        .....
   let "PERCENT= 100 * $LOOPCOUNT / $NUMFILES"
        echo $PERCENT
        let "LOOPCOUNT= $LOOPCOUNT + 1"

done)  | zenity --progress --pulsate \
  --title="Convert Files" \
  --text="Convert Files $NUMFILES" --percentage=1 --auto-close
 
  


Reply

Tags
array, loop, zenity


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP: Converting a PHP array into an HTML array koosha Programming 4 08-11-2009 08:47 AM
Nested loop with 2 counters for 2 array variables briana.paige Linux - Newbie 2 06-19-2009 07:38 AM
converting shell while loop to for loop farkus888 Programming 8 09-12-2007 02:30 AM
LXer: Tips from an RHCE: How can I make dd give me a progress report? LXer Syndicated Linux News 0 08-17-2007 06:50 AM
Problem with combining bash with zenity --progress chii-chan Programming 2 05-06-2005 03:12 AM


All times are GMT -5. The time now is 06:36 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration