The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
USN-784-1: ImageMagick vulnerability iBot Security Advisories (RSS) 0 06-08-2009 09:00 PM
USN-681-1: ImageMagick vulnerability iBot Security Advisories (RSS) 0 12-01-2008 01:30 PM
Padding Carriage return to the end of XML file dasj22 UNIX for Advanced & Expert Users 3 05-23-2008 10:31 AM
Padding zeros after removing commas in file pranag21 HP-UX 1 11-09-2005 10:22 PM
imageMagick? bob2003 UNIX for Dummies Questions & Answers 2 06-03-2003 02:59 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-20-2009
jsells20 jsells20 is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 9
Imagemagick File Padding Issue

Hello, I'm having a problem figuring out the syntax for padding 10-99. Everything else in the program works fine so I want to focus in on just this part of the code. Below is a snippet of the code that I am having problems with. I appreciate all the help I can get. Thank you.

The script basically takes an image and adds the convert charcoal filter and spits out a sequence the user specifies. Problem is if the frame goes over 100...the padding is thrown off since 100 is set for greater than or equal to, where 10-99 needs to be specified to a limit before 100.

I seen a for loop where it prints like so..

for i in {10..99} etc... but that will not work, it only prints and {10..99} does not work for an if statement.


##no problem here

if [ $count -lt 10 ]; then
convert ${IMGDIR}${IMG} -charcoal $count ${OUTDIR}${OUT}.000$count.jpg
fi


##cant figure out the arithmatic here!

if ( $count -ge 10 > 99 ); then
convert ${IMGDIR}${IMG} -charcoal $count ${OUTDIR}${OUT}.00$count.jpg
fi


##no problems here.

if [ $count -ge 100 ] ; then
convert ${IMGDIR}${IMG} -charcoal $count ${OUTDIR}${OUT}.0$count.jpg
fi
  #2 (permalink)  
Old 07-20-2009
durden_tyler's Avatar
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2009
Posts: 547
Quote:
Originally Posted by jsells20 View Post
...
##cant figure out the arithmatic here!

if ( $count -ge 10 > 99 ); then
...
fi
...

Code:
$
$ count=10
$ echo $count
10
$
$ while [ $count -le 20 ] ; do
>   echo $count
>   count=`expr $count + 1`
> done
10
11
12
13
14
15
16
17
18
19
20
$

tyler_durden
  #3 (permalink)  
Old 07-20-2009
jsells20 jsells20 is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 9
Can there be a while loop inside of a while loop? I already had one at the top. Heres the code edited. It's not correct, please correct me where im wrong.

count=$START
while [ $count -le $END ];
do
echo $count

if [ $count -lt 10 ]; then
convert ${IMGDIR}${IMG} -charcoal $count ${OUTDIR}${OUT}.000$count.jpg
fi

count=10
while [ $count -le 99 ]; do
convert ${IMGDIR}${IMG} -charcoal $count ${OUTDIR}${OUT}.00$count.jpg
count=`expr $count + 1`
done


if [ $count -ge 100 ] ; then
convert ${IMGDIR}${IMG} -charcoal $count ${OUTDIR}${OUT}.0$count.jpg
fi


SETTING=$(echo "scale=4; 1/50" | bc)
echo "processing frame: "$count""

let count=count+1

done
  #4 (permalink)  
Old 07-20-2009
durden_tyler's Avatar
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2009
Posts: 547
Quote:
Originally Posted by jsells20 View Post
Can there be a while loop inside of a while loop?
...

count=$START
while [ $count -le $END ];
do
echo $count

if [ $count -lt 10 ]; then
convert ${IMGDIR}${IMG} -charcoal $count ${OUTDIR}${OUT}.000$count.jpg
fi

count=10
while [ $count -le 99 ]; do
convert ${IMGDIR}${IMG} -charcoal $count ${OUTDIR}${OUT}.00$count.jpg
count=`expr $count + 1`
done


if [ $count -ge 100 ] ; then
convert ${IMGDIR}${IMG} -charcoal $count ${OUTDIR}${OUT}.0$count.jpg
fi


SETTING=$(echo "scale=4; 1/50" | bc)
echo "processing frame: "$count""

let count=count+1

done
So are those IF conditions inside the loop simply to ensure that the width of the number between ${OUT} and ".jpg" is constant ?

If so, then you could use "printf" and avoid those IF conditions -


Code:
$ 
$ OUT=myimage
$ count=1
$ 
$ while [ $count -le 100 ]; do
>   x=`printf "%s.%04d.jpg" $OUT $count`  # this is your output file, fixed width
>   echo $x                               # run your commands; "convert" etc.
>   count=`expr $count + 1`               # increment count
> done
myimage.0001.jpg
myimage.0002.jpg
myimage.0003.jpg
myimage.0004.jpg
myimage.0005.jpg
myimage.0006.jpg
myimage.0007.jpg
myimage.0008.jpg
myimage.0009.jpg
myimage.0010.jpg
myimage.0011.jpg
myimage.0012.jpg
...
... <output snipped for brevity>
...
myimage.0098.jpg
myimage.0099.jpg
myimage.0100.jpg
$ 
$

HTH,
tyler_durden
  #5 (permalink)  
Old 07-20-2009
BubbaJoe's Avatar
BubbaJoe BubbaJoe is offline
Registered User
  
 

Join Date: Oct 2008
Location: St Louis
Posts: 153
You can't do this because you reset count to 10 everytime. That won't get anything over 100 if count goes over 100.

Code:
count=10
while [ $count -le 99 ]; do
convert ${IMGDIR}${IMG} -charcoal $count ${OUTDIR}${OUT}.00$count.jpg
count=`expr $count + 1`
done

Maybe try


Code:
if [ $count -ge 10 && $count -le 99 ]
convert ${IMGDIR}${IMG} -charcoal $count ${OUTDIR}${OUT}.00$count.jpg
fi

  #6 (permalink)  
Old 07-20-2009
jsells20 jsells20 is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 9
Hmm..when I run this...



Code:
if [ $count -ge 10 && $count -le 99 ]; then
convert ${IMGDIR}${IMG} -charcoal $count ${OUTDIR}${OUT}.00$count.jpg
fi

It goes up to 9 and stops, my error from 0-10 is...


Code:
line 88: [: missing `]'


Last edited by jsells20; 07-20-2009 at 05:23 PM..
  #7 (permalink)  
Old 07-20-2009
BubbaJoe's Avatar
BubbaJoe BubbaJoe is offline
Registered User
  
 

Join Date: Oct 2008
Location: St Louis
Posts: 153
Sorry,
That shoudl be


Code:
if [ $count -ge 10 ] && [ $count -le 99 ] ;then

Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:28 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0