Re: Infinite loop in globbing
On 3/14/11 5:00 AM, Roman Rakus wrote: > $ locale > LANG=en_US.UTF-8 > LC_CTYPE="en_US.UTF-8" > LC_NUMERIC="en_US.UTF-8" > LC_TIME="en_US.UTF-8" > LC_COLLATE="en_US.UTF-8" > LC_MONETARY="en_US.UTF-8" > LC_MESSAGES="en_US.UTF-8" > LC_PAPER="en_US.UTF-8" > LC_NAME="en_US.UTF-8" > LC_ADDRESS="en_US.UTF-8" > LC_TELEPHONE="en_US.UTF-8" > LC_MEASUREMENT="en_US.UTF-8" > LC_IDENTIFICATION="en_US.UTF-8" > LC_ALL= > > $ echo $BASH_VERSION > 4.2.7(1)-release > > $ [$'\xFD'$'\xBA'] > ^C > > The bash 4.2 is in infinite loop. The bash 4.1 work well. Here's a minimal patch. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/ *** ../bash-4.2-patched/lib/glob/xmbsrtowcs.c 2010-05-30 18:36:27.0 -0400 --- lib/glob/xmbsrtowcs.c 2011-03-14 14:22:11.0 -0400 *** *** 174,180 wcslength = mbsnrtowcs(NULL, &tmp_p, nms, 0, &tmp_state); /* Conversion failed. */ ! if (wcslength == (size_t)-1) { free (wsbuf); *destp = NULL; --- 174,180 wcslength = mbsnrtowcs(NULL, &tmp_p, nms, 0, &tmp_state); /* Conversion failed. */ ! if (wcslength == 0 || wcslength == (size_t)-1) { free (wsbuf); *destp = NULL;
Re: vzctl enter hangs
On 3/14/11 5:15 AM, Henk van de Kamer wrote: >> I'd be interested in seeing what interrupted the select/read/write/ >> sigprocmask system calls in both processes. > > What exactly do you want. A full strace report? > > I'm trying to find the difference between 4.1.9 and 4.2.0 which causes > this behavior, but that is not simple because I don't know the order and > which differences I must combine. So this process will take a while... I have strace reports from another person. I just have to find time to look at them. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/
Re: set -x and parameter expansion
On 3/14/11 2:38 AM, Peggy Russell wrote: > This helps clarify the "set -x" difference below which show $r going through > parameter expansion done by the shell before the command [[ sees the > expression. > Okay... > > command [[ that > contains expr set -x > --- -- > [[ $? -eq r ]] + [[ 0 -eq r ]] * [[ used the contents of r which > was 0 > [[ $? -eq $r ]] + [[ 0 -eq 0 ]] > [[ $? -eq ${r:=0} ]]+ [[ 0 -eq 0 ]] > > For a user to see/trace r, they would either echo/printf, declare -p r, > or refer to it as $r (displayed by set -x). Yes. > Can users see more trace info on what happens within [[ (i.e.; [['s value for > r)? No. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/
Re: ReadLines and Substraction
benign dead code: >>> >>> If you can help me with this, will be very happy for that. Thanks in >>> advance. > > #!/usr/bin/env bash > > set -e > > if [[ $(type -t 'mapfile') != 'builtin' ]]; then > function mapfile > { > while getopts C:c: f > do > case $f in > C) cmd=$OPTARG;; > c) rep=$OPTARG;; > esac > done > shift $((--OPTIND)) > - i=0 > while read -r n > do - !((i % rep)) && eval "$cmd" + ((n % rep)) || eval "$cmd" > : $(($1[i++] = n)) > done > } > fi > > (((files = $#) >= 2)) > > while (($#)) > do > [[ $1 ]] > mapfile -C'let ++lno #' -c1 par_$# < <(egrep '^[0-9]+$' "$1") > shift > done > > ((lno && ((lno / files) == ${#par_1[@]}))) > > for i in ${!par_1[@]}; do > for ((j=1; j <= files-1; j++)); do > : $((par_$files[i] -= par_$j[i])) > done > printf '%d\n' $((par_$files[i])) > done > > exit
Re: Infinite loop in globbing
On 03/14/2011 10:06 AM, Chet Ramey wrote: >> On 03/14/2011 07:55 AM, Chet Ramey wrote: >>> The question is how to best handle it: punt immediately, or just treat it >>> as a single-byte character and move on. >> >> I vote single-byte character; after all, it's possible for a filename to >> contain that character, regardless of what your locale may be. > > Oh, it does do that. I meant in the context of attempting to convert the > entire string to a wide-char string. If the wide-char string conversion > fails, the globbing engine treats it as a sequence of single bytes. There > are efficiency improvements that can be made there, though. Yeah. But if we treat it as a single char and move on, we can at least "correctly" treat any further, legal character sequences. Not that anyone should have any particular expectations once they include an invalid character, if the further characters aren't in the same encoding as the actual filename... -- Micah J. Cowan http://micah.cowan.name/
Re: Infinite loop in globbing
> On 03/14/2011 07:55 AM, Chet Ramey wrote: > > The question is how to best handle it: punt immediately, or just treat it > > as a single-byte character and move on. > > I vote single-byte character; after all, it's possible for a filename to > contain that character, regardless of what your locale may be. Oh, it does do that. I meant in the context of attempting to convert the entire string to a wide-char string. If the wide-char string conversion fails, the globbing engine treats it as a sequence of single bytes. There are efficiency improvements that can be made there, though. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/
Re: ReadLines and Substraction
On Mon, Mar 14, 2011 at 6:38 AM, pk wrote: > yetcom wrote: > >> Hello Everyone, >> >> I have an issue regarding the bash. I have 2 different files and each >> of them involves some float point numbers for each lines. I want to >> subtract each line then put all the results into a file. The first >> line float number will be subtract with the first line of other file >> and the second with the other second... and etc... >> >> When I read both files with: >> >> cat ./Temp1.log | while read line; do >> >> cat ./Temp2.log | while read line; do >> >> #It reads the first line of temp1, I also need to read the >> first line of temp2. However, Temp2 will be read until the end of file >> so that I cannot read one by one for each lines of different files. >> >> done >> >> done >> >> >> If you can help me with this, will be very happy for that. Thanks in >> advance. #!/usr/bin/env bash set -e if [[ $(type -t 'mapfile') != 'builtin' ]] then function mapfile { while getopts C:c: f do case $f in C) cmd=$OPTARG;; c) rep=$OPTARG;; esac done shift $((--OPTIND)) i=0 while read -r n do !((i % rep)) && eval "$cmd" : $(($1[i++] = n)) done } fi (((files = $#) >= 2)) while (($#)) do [[ $1 ]] mapfile -C'let ++lno #' -c1 par_$# < <(egrep '^[0-9]+$' "$1") shift done ((lno && ((lno / files) == ${#par_1[@]}))) for i in ${!par_1[@]}; do for ((j=1; j <= files-1; j++)); do : $((par_$files[i] -= par_$j[i])) done printf '%d\n' $((par_$files[i])) done exit > > try > > paste -d '-' file1 file2 | bc > results > > >
Re: Infinite loop in globbing
On 03/14/2011 07:55 AM, Chet Ramey wrote: > The question is how to best handle it: punt immediately, or just treat it > as a single-byte character and move on. I vote single-byte character; after all, it's possible for a filename to contain that character, regardless of what your locale may be. -- Micah J. Cowan http://micah.cowan.name/
Re: Infinite loop in globbing
> >> $ [$'\xFD'$'\xBA'] > >> ^C > >> > >> The bash 4.2 is in infinite loop. The bash 4.1 work well. > > Can you give more details about the setup here? Does the glob match > > any files or not? > Just need to set some utf8 locales (I guess, tried and using > en_US.UTF-8). It doesn't matter if the file exists. > > In a NON-utf8 locale, with no matching files, I get: > > > > imadev:~$ [$'\xFD'$'\xBA'] > > bash: [ýº]: command not found > > > The same here. NON-utf8 locale working. bash-4.1 working also with utf8. > > bash-4.2 get stuck in xdupmbstowcs2() static function in do-while loop. > I know nearly nothing about wide chars so I don't know what is bad here. The 0xfd is an invalid multibyte character, so it can't be converted to a wide character. mbsnrtowcs returns 0, which is kind of a dodgy error (mbrlen returns -1 for the same character, for instance), but the code doesn't handle that case. The question is how to best handle it: punt immediately, or just treat it as a single-byte character and move on. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/
Re: Infinite loop in globbing
Greg Wooledge writes: > In a NON-utf8 locale Try using a utf8 locale. The problem is that xdupmbstowcs2 fails to handle partial multibyte sequences, where mbsnrtowcs may return zero. Andreas. -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
Re: Infinite loop in globbing
On 03/14/2011 02:59 PM, Greg Wooledge wrote: On Mon, Mar 14, 2011 at 10:00:14AM +0100, Roman Rakus wrote: $ locale LANG=en_US.UTF-8 LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL= $ echo $BASH_VERSION 4.2.7(1)-release $ [$'\xFD'$'\xBA'] ^C The bash 4.2 is in infinite loop. The bash 4.1 work well. Can you give more details about the setup here? Does the glob match any files or not? Just need to set some utf8 locales (I guess, tried and using en_US.UTF-8). It doesn't matter if the file exists. In a NON-utf8 locale, with no matching files, I get: imadev:~$ [$'\xFD'$'\xBA'] bash: [ýº]: command not found The same here. NON-utf8 locale working. bash-4.1 working also with utf8. bash-4.2 get stuck in xdupmbstowcs2() static function in do-while loop. I know nearly nothing about wide chars so I don't know what is bad here. Hopefully it helps. RR
Re: Infinite loop in globbing
On Mon, Mar 14, 2011 at 10:00:14AM +0100, Roman Rakus wrote: > $ locale > LANG=en_US.UTF-8 > LC_CTYPE="en_US.UTF-8" > LC_NUMERIC="en_US.UTF-8" > LC_TIME="en_US.UTF-8" > LC_COLLATE="en_US.UTF-8" > LC_MONETARY="en_US.UTF-8" > LC_MESSAGES="en_US.UTF-8" > LC_PAPER="en_US.UTF-8" > LC_NAME="en_US.UTF-8" > LC_ADDRESS="en_US.UTF-8" > LC_TELEPHONE="en_US.UTF-8" > LC_MEASUREMENT="en_US.UTF-8" > LC_IDENTIFICATION="en_US.UTF-8" > LC_ALL= > > $ echo $BASH_VERSION > 4.2.7(1)-release > > $ [$'\xFD'$'\xBA'] > ^C > > The bash 4.2 is in infinite loop. The bash 4.1 work well. Can you give more details about the setup here? Does the glob match any files or not? In a NON-utf8 locale, with no matching files, I get: imadev:~$ [$'\xFD'$'\xBA'] bash: [ýº]: command not found
Re: ReadLines and Substraction
yetcom wrote: > Hello Everyone, > > I have an issue regarding the bash. I have 2 different files and each > of them involves some float point numbers for each lines. I want to > subtract each line then put all the results into a file. The first > line float number will be subtract with the first line of other file > and the second with the other second... and etc... > > When I read both files with: > > cat ./Temp1.log | while read line; do > > cat ./Temp2.log | while read line; do > > #It reads the first line of temp1, I also need to read the > first line of temp2. However, Temp2 will be read until the end of file > so that I cannot read one by one for each lines of different files. > > done > > done > > > If you can help me with this, will be very happy for that. Thanks in > advance. try paste -d '-' file1 file2 | bc > results
Infinite loop in globbing
$ locale LANG=en_US.UTF-8 LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL= $ echo $BASH_VERSION 4.2.7(1)-release $ [$'\xFD'$'\xBA'] ^C The bash 4.2 is in infinite loop. The bash 4.1 work well. RR