LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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

Tags used in this thread
Popular LQ Tags , , ,

Reply
 
Thread Tools
Old 09-11-2009, 08:04 AM   #1
wonderfullyrich
LQ Newbie
 
Registered: Sep 2009
Location: Kampala
Distribution: Ubuntu Hardy Heron
Posts: 4
Thanked: 0
converting a for loop to an array so zenity can give progress


[Log in to get rid of this advertisement]
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
linux wonderfullyrich is offline  
Tag This Post , , ,
Reply With Quote
Old 09-12-2009, 09:26 AM   #2
catkin
Senior Member
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Slackware 13.0
Posts: 1,848
Blog Entries: 6
Thanked: 226
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.
linux catkin is offline     Reply With Quote
Thanked by:

Reply

Bookmarks


Thread Tools

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 09:47 AM
Nested loop with 2 counters for 2 array variables briana.paige Linux - Newbie 2 06-19-2009 08:38 AM
converting shell while loop to for loop farkus888 Programming 8 09-12-2007 03: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 07:50 AM
Problem with combining bash with zenity --progress chii-chan Programming 2 05-06-2005 04:12 AM


All times are GMT -5. The time now is 01:08 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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration