Re: bad case of parameter substitution with quotes (${p//x/y})

2010-06-23 Thread Chet Ramey
On 6/23/10 4:54 AM, Yves wrote: > Description: > I want to generate a "bash-proof" string by enclosing it in > single quotes and managing enclosed single quotes. Basically, I > would replace << word1 word'2 >> with << 'word1 word'"'"'2' >>. > I can't find the syntax for

Re: How to supply a string with space in it as parameter to a function?

2010-06-23 Thread Eric Blake
On 06/23/2010 07:01 PM, Andres P wrote: > On Wed, Jun 23, 2010 at 8:23 PM, Peng Yu wrote: >> Why printf is better than echo? Is this because printf is more robust than >> echo? > > Because if a string that is to be printed happens to be an echo flag, such > as -n or -e, there's no straight forwa

Re: How to supply a string with space in it as parameter to a function?

2010-06-23 Thread Andres P
On Wed, Jun 23, 2010 at 8:23 PM, Peng Yu wrote: > Why printf is better than echo? Is this because printf is more robust than > echo? Because if a string that is to be printed happens to be an echo flag, such as -n or -e, there's no straight forward way of escaping it such as with printf %s. And

Re: How to supply a string with space in it as parameter to a function?

2010-06-23 Thread Peng Yu
On Wed, Jun 23, 2010 at 5:43 PM, Chris F.A. Johnson wrote: > On Wed, 23 Jun 2010, Peng Yu wrote: > >> Hi, >> >> According to man bash, I thought that $@ instead of $* can help me >> pass a string with space as a parameter. But it is not. Would you >> please show me how to print 'b c' as a single a

Re: How to supply a string with space in it as parameter to a function?

2010-06-23 Thread Andres P
On Wed, Jun 23, 2010 at 6:07 PM, Peng Yu wrote: > #!/usr/bin/env bash > > function f { > #for i in $*; > for i in $@; > do >  echo $i > done > } > You can also omit the variable intirely: for i; do echo "$i" done In that case, the for loop will iterate over "$@".

Re: How to supply a string with space in it as parameter to a function?

2010-06-23 Thread Chris F.A. Johnson
On Wed, 23 Jun 2010, Peng Yu wrote: > Hi, > > According to man bash, I thought that $@ instead of $* can help me > pass a string with space as a parameter. But it is not. Would you > please show me how to print 'b c' as a single argument in the > following code? Always quote variable referenc

How to supply a string with space in it as parameter to a function?

2010-06-23 Thread Peng Yu
Hi, According to man bash, I thought that $@ instead of $* can help me pass a string with space as a parameter. But it is not. Would you please show me how to print 'b c' as a single argument in the following code? #!/usr/bin/env bash function f { #for i in $*; for i in $@; do echo $i done }

Re: The usage of {0..${#parameter}}

2010-06-23 Thread Greg Wooledge
On Wed, Jun 23, 2010 at 03:27:28PM -0500, Peng Yu wrote: > #for i in {0..${#parameter}}; This doesn't work. The parser does things in a very specific order. Brace expansion is done before parameter expansion. The parser sees 0..$ and that isn't a legitimate brace expansion range, so it doesn't p

Re: bad case of parameter substitution with quotes (${p//x/y})

2010-06-23 Thread Greg Wooledge
On Wed, Jun 23, 2010 at 10:54:50AM +0200, Yves wrote: > I want to generate a "bash-proof" string by enclosing it in > single quotes and managing enclosed single quotes. A better approach is to use: printf -v new_string %q "$original_string" printf %q is essentially the reverse of e

bad case of parameter substitution with quotes (${p//x/y})

2010-06-23 Thread Yves
From: pub...@yeti.selfip.net To: bug-bash@gnu.org Configuration Information [Automatically generated, do not change]: FALSE!!! Machine: i586 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i586' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i586-mandriva-linux-

The usage of {0..${#parameter}}

2010-06-23 Thread Peng Yu
The commented line in the following bash script is not working. I notice the following description from man bash and I think that it is the reason. But I'm not completely sure. Would you please confirm it for me? Also, I'm wondering where this decision was made. Can't bash be made more powerful by

Re: String replacements leak small amounts of memory each time

2010-06-23 Thread Matthew Woehlke
Chet Ramey wrote: On 6/22/10 6:57 PM, Matthew Woehlke wrote: No question something bad is going on here. You're right. I found and fixed it. It wasn't where I was looking initially. The fix will be in the next bash release and may come out as a patch. Also, when run under valgrind, I see

Re: [bash-bug] A note for read builtin

2010-06-23 Thread Dr. Werner Fink
On Wed, Jun 23, 2010 at 10:00:12AM +0200, Werner Fink wrote: > On Tue, Jun 22, 2010 at 04:50:54PM -0400, Chet Ramey wrote: > > On 6/18/10 10:05 AM, Dr. Werner Fink wrote: > > > > > as now is visible the last command in the pipe sequence done > > > in the bash is a real sub process whereas in the k

Re: A note for read builtin

2010-06-23 Thread Dr. Werner Fink
On Tue, Jun 22, 2010 at 04:50:54PM -0400, Chet Ramey wrote: > On 6/18/10 10:05 AM, Dr. Werner Fink wrote: > > > as now is visible the last command in the pipe sequence done > > in the bash is a real sub process whereas in the ksh it is not. > > > > The question rises: Why does the bash require a