public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-user] OT - Question about new bash
@ 2006-01-29 17:43 Michael Sullivan
  2006-01-29 17:48 ` fire-eyes
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Michael Sullivan @ 2006-01-29 17:43 UTC (permalink / raw
  To: gentoo-user

I wrote a script a long time ago for resizing pictures uploaded to a
certain directory on my server box.  The script was supposed to check to
see if any JPG files in the directory had not been resized, and if they
hadn't, it was supposed to resize them.  It did some other stuff, but
that was the important thing.  It worked fine until the recent bash
upgrade and now it gives me an error.  Here is the script:

michael@bullet ~ $ cat system/resizepics
#!/bin/bash
OLD_DIR=$PWD
cd /home/michael/unfiledPics

if [ ! -d current ]; then
   mkdir -p current/mini
fi

if [ ! `ls -l | wc -l` -le 2 ]; then
   for x in *.JPG; do
      if [ ! -e current/$x ]; then
         convert "$x" -thumbnail 200x200 -verbose current/mini/mini-"$x"
         convert "$x" -thumbnail 640x480 -verbose current/"$x";
      fi
   done
fi


if [ `ls -l | wc -l` -ge 12 ]; then
   today=`date '+%m%d%y'`
   mv current $today
   mv $today /home/michael/webspace/html/camera
   mkdir -p /home/michael/unfiledPics/current/mini
   rm /home/michael/unfiledPics/*.JPG
fi

cd $OLD_DIR

As I said, before the bash upgrade this worked perfectly.  Now, when I
try to run it, I get this:

michael@bullet ~ $ system/resizepics
system/resizepics: line 11: [: too many arguments
system/resizepics: line 11: [: too many arguments


The error is printed twice because there are two .JPG being checked, but
I'm not sure why the error is occurring in the first place.  Line 11
says:

if [ ! -e current/$x ]; then

This used to mean "if a file named "current/<whatever $x is>" does not
exist, then execute the following block", but it keeps tripping on this
line.  Was the -e switch deprecated or something?  What should it be?
If it matters, my /bin/bash version is

michael@bullet ~ $ bash --version
GNU bash, version 3.00.16(1)-release (i586-pc-linux-gnu)
Copyright (C) 2004 Free Software Foundation, Inc.

Please help!


-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-user] OT - Question about new bash
  2006-01-29 17:43 [gentoo-user] OT - Question about new bash Michael Sullivan
@ 2006-01-29 17:48 ` fire-eyes
  2006-01-29 18:05 ` znx
  2006-01-29 18:38 ` [gentoo-user] OT - Question about new bash Alexander Skwar
  2 siblings, 0 replies; 9+ messages in thread
From: fire-eyes @ 2006-01-29 17:48 UTC (permalink / raw
  To: gentoo-user

Michael Sullivan wrote:
> I wrote a script a long time ago for resizing pictures uploaded to a
> certain directory on my server box.  The script was supposed to check to
> see if any JPG files in the directory had not been resized, and if they
> hadn't, it was supposed to resize them.  It did some other stuff, but
> that was the important thing.  It worked fine until the recent bash
> upgrade and now it gives me an error.  Here is the script:
> 
> michael@bullet ~ $ cat system/resizepics
> #!/bin/bash
> OLD_DIR=$PWD
> cd /home/michael/unfiledPics
> 
> if [ ! -d current ]; then
>    mkdir -p current/mini
> fi
> 
> if [ ! `ls -l | wc -l` -le 2 ]; then
>    for x in *.JPG; do
>       if [ ! -e current/$x ]; then
>          convert "$x" -thumbnail 200x200 -verbose current/mini/mini-"$x"
>          convert "$x" -thumbnail 640x480 -verbose current/"$x";
>       fi
>    done
> fi
> 
> 
> if [ `ls -l | wc -l` -ge 12 ]; then
>    today=`date '+%m%d%y'`
>    mv current $today
>    mv $today /home/michael/webspace/html/camera
>    mkdir -p /home/michael/unfiledPics/current/mini
>    rm /home/michael/unfiledPics/*.JPG
> fi
> 
> cd $OLD_DIR
> 
> As I said, before the bash upgrade this worked perfectly.  Now, when I
> try to run it, I get this:
> 
> michael@bullet ~ $ system/resizepics
> system/resizepics: line 11: [: too many arguments
> system/resizepics: line 11: [: too many arguments
> 
> 
> The error is printed twice because there are two .JPG being checked, but
> I'm not sure why the error is occurring in the first place.  Line 11
> says:
> 
> if [ ! -e current/$x ]; then
> 
> This used to mean "if a file named "current/<whatever $x is>" does not
> exist, then execute the following block", but it keeps tripping on this
> line.  Was the -e switch deprecated or something?  What should it be?
> If it matters, my /bin/bash version is
> 
> michael@bullet ~ $ bash --version
> GNU bash, version 3.00.16(1)-release (i586-pc-linux-gnu)
> Copyright (C) 2004 Free Software Foundation, Inc.
> 
> Please help!

I'm not sure myself, but a better place to ask might be freenode's #bash

;)

Good luck

-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-user] OT - Question about new bash
  2006-01-29 17:43 [gentoo-user] OT - Question about new bash Michael Sullivan
  2006-01-29 17:48 ` fire-eyes
@ 2006-01-29 18:05 ` znx
  2006-01-29 18:34   ` [gentoo-user] OT - Question about new bash [SOLVED] Michael Sullivan
  2006-01-29 18:38 ` [gentoo-user] OT - Question about new bash Alexander Skwar
  2 siblings, 1 reply; 9+ messages in thread
From: znx @ 2006-01-29 18:05 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 264 bytes --]

Hi,

   for x in *.JPG; do
>       if [ ! -e current/$x ]; then


I can't see anything wrong with this in particular, one thing that springs
to mind is to quote the string that you are testing:

for x in *.JPG; do
  if [ ! -e "current/$x" ]; then

Hope that helps

[-- Attachment #2: Type: text/html, Size: 556 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-user] OT - Question about new bash [SOLVED]
  2006-01-29 18:05 ` znx
@ 2006-01-29 18:34   ` Michael Sullivan
  2006-01-29 19:09     ` Norberto Bensa
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Sullivan @ 2006-01-29 18:34 UTC (permalink / raw
  To: gentoo-user

On Sun, 2006-01-29 at 18:05 +0000, znx wrote:
> Hi,
> 
>            for x in *.JPG; do
>               if [ ! -e current/$x ]; then
> 
> I can't see anything wrong with this in particular, one thing that
> springs to mind is to quote the string that you are testing:
> 
> for x in *.JPG; do
>   if [ ! -e "current/$x" ]; then
> 
> Hope that helps
> 

Yep, that worked!  Thanks!  Hmm, I wonder why it worked before?


-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-user] OT - Question about new bash
  2006-01-29 17:43 [gentoo-user] OT - Question about new bash Michael Sullivan
  2006-01-29 17:48 ` fire-eyes
  2006-01-29 18:05 ` znx
@ 2006-01-29 18:38 ` Alexander Skwar
  2 siblings, 0 replies; 9+ messages in thread
From: Alexander Skwar @ 2006-01-29 18:38 UTC (permalink / raw
  To: gentoo-user

Michael Sullivan wrote:

> As I said, before the bash upgrade this worked perfectly.  Now, when I
> try to run it, I get this:
> 
> michael@bullet ~ $ system/resizepics
> system/resizepics: line 11: [: too many arguments
> system/resizepics: line 11: [: too many arguments

I don't get this error, when I run your script. How
are the files named? Do they have spaces in the file
name? If so - and even if not - I'd *STRONGLY* suggest
to enclose current/$x in quotes, like so:

if [ ! -e "current/$x" ]; then

Alexander Skwar
-- 
R Tape loading error, 0:1
-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-user] OT - Question about new bash [SOLVED]
  2006-01-29 18:34   ` [gentoo-user] OT - Question about new bash [SOLVED] Michael Sullivan
@ 2006-01-29 19:09     ` Norberto Bensa
  2006-01-30 14:11       ` znx
  0 siblings, 1 reply; 9+ messages in thread
From: Norberto Bensa @ 2006-01-29 19:09 UTC (permalink / raw
  To: gentoo-user; +Cc: Michael Sullivan

Michael Sullivan wrote:
> > for x in *.JPG; do
> >   if [ ! -e "current/$x" ]; then
> >
> > Hope that helps
>
> Yep, that worked!  Thanks!  Hmm, I wonder why it worked before?

Perhaps you got some file named: hey I am a long file name with spaces.jpg ;)

-- 
Norberto Bensa
Ciudad de Buenos Aires, Argentina
-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-user] OT - Question about new bash [SOLVED]
  2006-01-29 19:09     ` Norberto Bensa
@ 2006-01-30 14:11       ` znx
  2006-01-30 14:19         ` Alexander Skwar
  0 siblings, 1 reply; 9+ messages in thread
From: znx @ 2006-01-30 14:11 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 477 bytes --]

On 29/01/06, Norberto Bensa <nbensa@gmx.net> wrote:
>
> Perhaps you got some file named: hey I am a long file name with spaces.jpg;)
>

No it can't be that, see the "for" before hand, that will separate at
whitespace by default (unless you tamper with IFS), so the variable tested
will be without whitespace, I can only guess its a charset or similar that
is causing the issue.

Anyway, good to see that it sorted it, point for the future, quote your
variables in [ ] 's :)

z

[-- Attachment #2: Type: text/html, Size: 770 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-user] OT - Question about new bash [SOLVED]
  2006-01-30 14:11       ` znx
@ 2006-01-30 14:19         ` Alexander Skwar
  2006-01-31  2:14           ` znx
  0 siblings, 1 reply; 9+ messages in thread
From: Alexander Skwar @ 2006-01-30 14:19 UTC (permalink / raw
  To: gentoo-user

znx wrote:

> No it can't be that, see the "for" before hand, that will separate at
> whitespace by default

No, it won't. Try it.

> (unless you tamper with IFS), so the variable
> tested will be without whitespace,

No, it won't.


> I can only guess its a charset or
> similar that is causing the issue.

I rather suppose, that he has filenames with spaces.

> Anyway, good to see that it sorted it, point for the future, quote your
> variables in [ ] 's :)

Of course - ever and always quote variables, unless you can be
totally certain about the contents.

Alexander Skwar
-- 
    You're gonna have to answer to the Coca-Cola company.
        -- Colonel "Bat" Guano, "Dr. Strangelove or: How I Learned to
           Stop Worrying and Love the Bomb"
-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-user] OT - Question about new bash [SOLVED]
  2006-01-30 14:19         ` Alexander Skwar
@ 2006-01-31  2:14           ` znx
  0 siblings, 0 replies; 9+ messages in thread
From: znx @ 2006-01-31  2:14 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 917 bytes --]

First off.. OH!

On 30/01/06, Alexander Skwar <listen@alexander.skwar.name> wrote:
>
> znx wrote:
>
> > No it can't be that, see the "for" before hand, that will separate at
> > whitespace by default
>
> No, it won't. Try it.


True, ok so it did? and not now with bash3, I presume this is why it
"worked" before and doesn't now?

> (unless you tamper with IFS), so the variable
> > tested will be without whitespace,
>
> No, it won't.


See above!

> I can only guess its a charset or
> > similar that is causing the issue.
>
> I rather suppose, that he has filenames with spaces.


Absolutely!

> Anyway, good to see that it sorted it, point for the future, quote your
> > variables in [ ] 's :)
>
> Of course - ever and always quote variables, unless you can be
> totally certain about the contents.


:P

Alexander Skwar


My apologies Alexander, I shall move my head into a bucket now for around 4
days.

Thanks

[-- Attachment #2: Type: text/html, Size: 1946 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2006-01-31  2:21 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-01-29 17:43 [gentoo-user] OT - Question about new bash Michael Sullivan
2006-01-29 17:48 ` fire-eyes
2006-01-29 18:05 ` znx
2006-01-29 18:34   ` [gentoo-user] OT - Question about new bash [SOLVED] Michael Sullivan
2006-01-29 19:09     ` Norberto Bensa
2006-01-30 14:11       ` znx
2006-01-30 14:19         ` Alexander Skwar
2006-01-31  2:14           ` znx
2006-01-29 18:38 ` [gentoo-user] OT - Question about new bash Alexander Skwar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox