Wrong variable expansion inside quotation marks

2008-02-13 Thread Reuti

Hi,

I have one system with:

[EMAIL PROTECTED]:~> bash --version
GNU bash, version 3.00.16(1)-release (i586-suse-linux)
Copyright (C) 2004 Free Software Foundation, Inc.

[EMAIL PROTECTED]:~> hallo=hallo
[EMAIL PROTECTED]:~> rr=r
[EMAIL PROTECTED]:~> tt="${rr:0:${#rr}-1}$hallo"
[EMAIL PROTECTED]:~> echo ${#tt}
5

This is what I expect. But in an newer bash:

[EMAIL PROTECTED]:~$ bash --version
GNU bash, version 3.1.17(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.

[EMAIL PROTECTED]:~$ hallo=hallo
[EMAIL PROTECTED]:~$ rr=r
[EMAIL PROTECTED]:~$ tt="${rr:0:${#rr}-1}$hallo"
[EMAIL PROTECTED]:~$ echo ${#tt}
6

There is suddenly a 6th illegal character generated (in the original  
routine its purpose was to remove the last character of $rr (which is  
als at least one character long). But only if rr is one character  
long - if it's longer all is fine again.


I circumvent the problem for now by removing the quotation marks:

[EMAIL PROTECTED]:~$ tt=${rr:0:${#rr}-1}$hallo
[EMAIL PROTECTED]:~$ echo ${#tt}
5


-- Reuti




broken pipe

2008-02-13 Thread Michael Potter
Bash Bunch,

I googled a bit and it see this problem asked several times, but I
never really saw a slick solution:

given this:

set -o pipefail
find / -type f -print 2>&1 |head -20
echo ${PIPESTATUS[*]}

prints this:
141 0

find fails because it has a bunch of output, but head only will accept
the first n lines.

This is a problem for me because I have trap ERR & errexit & pipefail activated.

The solution I will use will be to write the find output to a file,
then run head on it.

I am hoping that someone on the group has a more graceful solution.

BTW: I am not using find in my real script.  I just used that here so
anyone could reproduce the problem.

-- 
Michael Potter




Re: broken pipe

2008-02-13 Thread Brian J. Murrell
On Wed, 2008-02-13 at 16:00 -0500, Brian J. Murrell wrote:
> 
> find / -type f -print 2>&1 | head -20 || true

Doh!

This of course won't work.  The first solution should though.

b.



signature.asc
Description: This is a digitally signed message part


Re: broken pipe

2008-02-13 Thread Paul Jarc
"Brian J. Murrell" <[EMAIL PROTECTED]> wrote:
> It is a shame for this particular reason that head does not (perhaps as
> an option) consume it's input after displaying the 20 lines.

You can do that with sed:
... | sed '21,$d'


paul




Re: broken pipe

2008-02-13 Thread Brian J. Murrell
On Wed, 2008-02-13 at 14:56 -0600, Michael Potter wrote:
> Bash Bunch,
> 
> I googled a bit and it see this problem asked several times, but I
> never really saw a slick solution:
> 
> given this:
> 
> set -o pipefail
> find / -type f -print 2>&1 |head -20
> echo ${PIPESTATUS[*]}
> 
> prints this:
> 141 0
> 
> find fails because it has a bunch of output, but head only will accept
> the first n lines.
> 
> This is a problem for me because I have trap ERR & errexit & pipefail 
> activated.
> 
> The solution I will use will be to write the find output to a file,
> then run head on it.

How about:

find / -type f -print 2>&1 | (head -20; cat >/dev/null)

or

find / -type f -print 2>&1 | head -20 || true

> I am hoping that someone on the group has a more graceful solution.

It is a shame for this particular reason that head does not (perhaps as
an option) consume it's input after displaying the 20 lines.

b.



signature.asc
Description: This is a digitally signed message part


Re: Wrong variable expansion inside quotation marks

2008-02-13 Thread Chet Ramey

Reuti wrote:

Hi,

I have one system with:

[EMAIL PROTECTED]:~> bash --version
GNU bash, version 3.00.16(1)-release (i586-suse-linux)
Copyright (C) 2004 Free Software Foundation, Inc.

[EMAIL PROTECTED]:~> hallo=hallo
[EMAIL PROTECTED]:~> rr=r
[EMAIL PROTECTED]:~> tt="${rr:0:${#rr}-1}$hallo"
[EMAIL PROTECTED]:~> echo ${#tt}
5

This is what I expect. But in an newer bash:

[EMAIL PROTECTED]:~$ bash --version
GNU bash, version 3.1.17(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.

[EMAIL PROTECTED]:~$ hallo=hallo
[EMAIL PROTECTED]:~$ rr=r
[EMAIL PROTECTED]:~$ tt="${rr:0:${#rr}-1}$hallo"
[EMAIL PROTECTED]:~$ echo ${#tt}
6


The current version of bash (3.2.33) behaves correctly, like bash-3.0.

Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
   Live Strong.  No day but today.
Chet Ramey, ITS, CWRU[EMAIL PROTECTED]http://cnswww.cns.cwru.edu/~chet/