Re: [Fwd: [PATCH] arithmetic - logical shift]

2008-10-21 Thread Pádraig Brady
Chet Ramey wrote:
 Pádraig Brady wrote:
  Original Message 
 Date: Tue, 07 Oct 2008 11:55:51 +0100
 From: Pádraig Brady [EMAIL PROTECTED]
 To: Chet Ramey [EMAIL PROTECTED]
 CC: [EMAIL PROTECTED]

 I was just discussing bit shifting with Tim Hockin using shell
 arithmetic expansion, and he pointed out that bash and ksh
 use arithmetic rather than logical shift for the  operator.
 
 Actually, bash and ksh use whatever the native C compiler implements,
 since both just translate the  and  into the same operators
 internally.
 
 I don't see a really compelling reason to change, since, as you say,
 the standard requires signed long ints.

Well that means the result is compiler dependent.
So scripts could give different results on another
platform, or less often within a platform.

Also arithmetic right shift is not useful.

Pádraig.





Re: Interrupted system call when piping to grep

2008-10-21 Thread Chet Ramey
Tanel Rebane wrote:
 Hello,
 
 a problem occurs when running the following bash shell script:
 #!/usr/bin/env bash
 for (( q = 0 ; q  1 ; q++ )); do
 while read -d '' z; do result+=($z); done  (printf 
 %s\000\n hej | grep -a 'hej')
 done
 
 For some reason the following output is printed:
 ./test.bash: line 4: /var/tmp//sh-np-2094024698: Interrupted system call
 ./test.bash: line 4: /var/tmp//sh-np-1952491205: Interrupted system call
 ./test.bash: line 4: /var/tmp//sh-np-2936939995: Interrupted system call
 ./test.bash: line 4: /var/tmp//sh-np-255058020: Interrupted system call
 etc etc...
 
 This seems to only happen when piping to grep. I'm using FBSD 6.2-STABLE, 
 Bash 3.2.33(0)-release and grep (GNU grep) 2.5.1-FreeBSD.

I took a look at this, and it's not just due to the grep.  I think it's a
timing problem, but I can't tell what signal is interrupting the open.  I
thought it might be SIGCHLD, but I don't think so now.  It just seems that
FreeBSD's named pipe implementation is a bit fragile.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer

Chet Ramey, ITS, CWRU[EMAIL PROTECTED]http://cnswww.cns.cwru.edu/~chet/




implementing flow control in bash

2008-10-21 Thread Tony Zanella
Hello all,
I'm sure this isn't a bug, but just my inability to wrap my head
around enough of bash flow control:
I wrote the following shell script to find all gifs in a directory.
Then use identify from imagemagick to grab the gif width. Then,
print the image name and width to a file.

  for i in `find . -name \*gif`; do identify -format $i %w $i; done
 results.txt

Then, I used a ruby script to cull only those images with a width over
570 pixels. So, problem solved, but I wanted to see if I could do it
all in bash.
More specifically, (if this makes sense) I want to do identify
-format $i %w $i only for those $i %w where %w is  570.

The above script will give me output like:

  image1.gif 360
  image2.gif 780

But I want it to give me:

  image1.gif 360

In pseudo-code, I want something like:

  for i in `find . -name \*gif`; do identify -format $i %w $i if [%w
 570]; done  results.txt

Any suggestions?
Tony




Re: implementing flow control in bash

2008-10-21 Thread Bernd Eggink

Tony Zanella schrieb:

Hello all,
I'm sure this isn't a bug, but just my inability to wrap my head
around enough of bash flow control:
I wrote the following shell script to find all gifs in a directory.
Then use identify from imagemagick to grab the gif width. Then,
print the image name and width to a file.

  for i in `find . -name \*gif`; do identify -format $i %w $i; done

results.txt


Then, I used a ruby script to cull only those images with a width over
570 pixels. So, problem solved, but I wanted to see if I could do it
all in bash.
More specifically, (if this makes sense) I want to do identify
-format $i %w $i only for those $i %w where %w is  570.

The above script will give me output like:

  image1.gif 360
  image2.gif 780

But I want it to give me:

  image1.gif 360

In pseudo-code, I want something like:

  for i in `find . -name \*gif`; do identify -format $i %w $i if [%w

570]; done  results.txt


for i in $(find -name '*.gif')
do
w=$(identify -format %w $i)
(( w  570 ))  echo $i $w
done

Hope that helps,
Bernd

--
Bernd Eggink
http://sudrala.de