a problem of mapfile

2013-01-11 Thread Ma Shimiao
Configuration Information : Machine: i686 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' -DCONF_OSTYPE='linux-gnu' -D$ uname output: Linux ubuntu 3.2.0-35-generic #55-Ubuntu SMP Wed Dec 5 17:45:18 UTC 2012 i6$ Machine Type: i686-pc-linux-gnu Bash Versi

Re: a problem of mapfile

2013-01-11 Thread Greg Wooledge
On Fri, Jan 11, 2013 at 10:21:55PM +0800, Ma Shimiao wrote: > I used commands as follows: > $seq 5 | mapfile -C echo -c1 > 0 1 > > 1 2 > > 2 3 > > 3 4 > > 4 5 > > I would have expectd 1,2,3,4,5 above from the"help mapfile". > Is it a bug of mapfile? The help says: When CALLBACK is evalu

Re: a problem of mapfile

2013-01-11 Thread Ma Shimiao
Thank Greg for your answer very much. This problem has confused me for 2 days. That seems I didn't read the manpage carefully. On 01/11/2013 10:54 PM, Greg Wooledge wrote: On Fri, Jan 11, 2013 at 10:21:55PM +0800, Ma Shimiao wrote: I used commands as follows: $seq 5 | mapfile -C echo -c1 0 1

Assignment errors with no additional words expanded in non-POSIX mode fails to abort

2013-01-11 Thread Dan Douglas
Whether or not this type of error aborts depends upon there being an actual newline. $ bash -c 'echo pre; foo=$((8#9)); echo post' 2>&1 pre bash: 8#9: value too great for base (error token is "8#9") $ bash -c $'echo pre\nfoo=$((8#9))\necho post' 2>&1 pre bash: line 1: 8#9

typeset -p on an empty integer variable is an error. (plus -v test w/ array elements)

2013-01-11 Thread Dan Douglas
Bash treats the variable as essentially undefined until given at least an empty value. $ bash -c 'typeset -i x; [[ -v x ]]; echo "$?, ${x+foo}"; typeset -p x' 1, bash: line 0: typeset: x: not found $ ksh -c 'typeset -i x; [[ -v x ]]; echo "$?, ${x+foo}"; typeset -p x' 0, t

printf %q represents null argument as empty string.

2013-01-11 Thread Dan Douglas
$ set --; printf %q\\n "$@" '' printf should perhaps only output '' when there is actually a corresponding empty argument, else eval "$(printf %q ...)" and similar may give different results than expected. Other shells don't output '', even mksh's ${var@Q} expansion. Zsh's ${(q)var} does

Re: printf %q represents null argument as empty string.

2013-01-11 Thread John Kearney
Am 11.01.2013 19:38, schrieb Dan Douglas: > $ set --; printf %q\\n "$@" > '' > > printf should perhaps only output '' when there is actually a corresponding > empty argument, else eval "$(printf %q ...)" and similar may give different > results than expected. Other shells don't output '',

Re: typeset -p on an empty integer variable is an error. (plus -v test w/ array elements)

2013-01-11 Thread John Kearney
Am 11.01.2013 19:27, schrieb Dan Douglas: > Bash treats the variable as essentially undefined until given at least an > empty value. > > $ bash -c 'typeset -i x; [[ -v x ]]; echo "$?, ${x+foo}"; typeset -p x' > 1, > bash: line 0: typeset: x: not found > $ ksh -c 'typeset -i x; [[ -

Re: printf %q represents null argument as empty string.

2013-01-11 Thread Dan Douglas
On Friday, January 11, 2013 09:39:00 PM John Kearney wrote: > Am 11.01.2013 19:38, schrieb Dan Douglas: > > $ set --; printf %q\\n "$@" > > '' > > > > printf should perhaps only output '' when there is actually a corresponding > > empty argument, else eval "$(printf %q ...)" and similar ma

checkwinsize only works in interactive shells

2013-01-11 Thread Greg Wooledge
shopt -s checkwinsize only works in interactive shells. However, this is not mentioned in the manual. Tested in Bash 4.2.37. #!/bin/bash trap 'echo "COLUMNS is now <$COLUMNS>"' WINCH test -z "$COLUMNS" && COLUMNS=$(tput cols) shopt -s checkwinsize while sleep 1; do :; done Run in a terminal, re

Re: typeset -p on an empty integer variable is an error. (plus -v test w/ array elements)

2013-01-11 Thread Dan Douglas
On Friday, January 11, 2013 09:48:32 PM John Kearney wrote: > Am 11.01.2013 19:27, schrieb Dan Douglas: > > Bash treats the variable as essentially undefined until given at least an > > empty value. > > > > $ bash -c 'typeset -i x; [[ -v x ]]; echo "$?, ${x+foo}"; typeset -p x' > > 1, > >

Re: printf %q represents null argument as empty string.

2013-01-11 Thread Chet Ramey
On 1/11/13 4:05 PM, Dan Douglas wrote: > > I don't understand what you mean. The issue I'm speaking of is that printf %q > produces a quoted empty string both when given no args and when given one > empty arg. A quoted "$@" with no positional parameters present expands to > zero > words (and

Re: checkwinsize only works in interactive shells

2013-01-11 Thread Chet Ramey
On 1/11/13 4:13 PM, Greg Wooledge wrote: > shopt -s checkwinsize only works in interactive shells. However, this > is not mentioned in the manual. Yes, that's true. This was reported in June, and the development versions since then have been changed to make it work in non-interactive shells as w

Re: checkwinsize only works in interactive shells

2013-01-11 Thread DJ Mills
On Fri, Jan 11, 2013 at 4:43 PM, Chet Ramey wrote: > On 1/11/13 4:13 PM, Greg Wooledge wrote: > > shopt -s checkwinsize only works in interactive shells. However, this > > is not mentioned in the manual. > > Yes, that's true. This was reported in June, and the development versions > since then

Re: printf %q represents null argument as empty string.

2013-01-11 Thread Dan Douglas
On Friday, January 11, 2013 04:37:56 PM Chet Ramey wrote: > On 1/11/13 4:05 PM, Dan Douglas wrote: > > > > > I don't understand what you mean. The issue I'm speaking of is that printf > > %q > > produces a quoted empty string both when given no args and when given one > > empty arg. A quoted "

Re: checkwinsize only works in interactive shells

2013-01-11 Thread Chet Ramey
On 1/11/13 4:46 PM, DJ Mills wrote: > Will they still be updated on WINCH without checkwinsize, as well? And will > they be set by default, or continue to be unset in scripts unless set > manually? The only thing that's changed is that checkwinsize works in non-interactive shells. SIGWINCH stil

Re: checkwinsize only works in interactive shells

2013-01-11 Thread DJ Mills
On Fri, Jan 11, 2013 at 4:51 PM, Chet Ramey wrote: > On 1/11/13 4:46 PM, DJ Mills wrote: > > > Will they still be updated on WINCH without checkwinsize, as well? And > will > > they be set by default, or continue to be unset in scripts unless set > manually? > > The only thing that's changed is t

Re: typeset -p on an empty integer variable is an error. (plus -v test w/ array elements)

2013-01-11 Thread Chet Ramey
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 1/11/13 1:27 PM, Dan Douglas wrote: > Bash treats the variable as essentially undefined until given at least an > empty value. This is what Posix says: A variable is a parameter denoted by a name. A parameter is set if it has an

Re: checkwinsize only works in interactive shells

2013-01-11 Thread Chet Ramey
On 1/11/13 4:58 PM, DJ Mills wrote: > As of right now, WINCH will not update COLUMNS or LINES in a > non-interactive shell. > > I've had to use: > trap 'COLUMNS=$(tput cols); LINES=$(tput lines)' WINCH > to get that behavior. And that hasn't changed. Maybe I should look at changing it. Chet

Re: printf %q represents null argument as empty string.

2013-01-11 Thread John Kearney
Am 11.01.2013 22:05, schrieb Dan Douglas: > On Friday, January 11, 2013 09:39:00 PM John Kearney wrote: >> Am 11.01.2013 19:38, schrieb Dan Douglas: >>> $ set --; printf %q\\n "$@" >>> '' >>> >>> printf should perhaps only output '' when there is actually a > corresponding >>> empty argume

Re: typeset -p on an empty integer variable is an error. (plus -v test w/ array elements)

2013-01-11 Thread John Kearney
Am 11.01.2013 22:34, schrieb Dan Douglas: > On Friday, January 11, 2013 09:48:32 PM John Kearney wrote: >> Am 11.01.2013 19:27, schrieb Dan Douglas: >>> Bash treats the variable as essentially undefined until given at least an >>> empty value. >>> >>> $ bash -c 'typeset -i x; [[ -v x ]]; echo

Re: printf %q represents null argument as empty string.

2013-01-11 Thread Dan Douglas
On Saturday, January 12, 2013 02:35:34 AM John Kearney wrote: > so there is always at least one word or one arg, just because its "${@}" > should not affect this behavior. ... > printf "%q" "${@}" > becomes > printf "%q" "" > > which is correct as '' No, "${@}" doesn't always become at least one