bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem:bash_builtin:mapfile:option_C:executing_indxed_array_value


From: Bruxo Pi
Subject: Problem:bash_builtin:mapfile:option_C:executing_indxed_array_value
Date: Sun, 31 Jul 2011 06:55:47 -0700 (PDT)

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
-DHAVE_CONFIG_H   -I.  -I../bash -I../bash/include -I../bash/lib   -g -O2 -Wall
uname output: Linux mach 2.6.38-10-generic #46-Ubuntu SMP Tue Jun 28 15:07:17 
UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 4.2
Patch Level: 8
Release Status: release

Description:
Bash bultin 'mapfile', with -C option, executes any value read from stdin. The 
usagem - from bash_ref.pdf - is:
    mapfile [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c 
quantum] [array]
My command:
   $ mapfile -t -n 4 -c 2 -C let _par++_vet
Well, when it reads the second entry, from stdin, and IF the entry is equal to 
or contains 'ç' or 'Ç', it complains, eath 2 line (normal), with the erro 
message (not normal):
./test.sh: linha 8: let: Ç: erro de sintaxe: operando esperado (token com erro 
é "Ç")
[translated: $0: line 8: let: Ç: syntax error: expected operand (error token 
with "Ç")]


It seems like bash executes 'let' builtin with the name of my array. So, I 
tried to isolate the command 'let _par++':
   $ mapfile -t -n 4 -c 2 -C 'let _par++' _vet
Something. An error ocurred also with the value 09 (it interprates as octal, 
because 09 does not exist).
Then, I tried to put the name of my array befor the -C option:
   $ mapfile -t -n 4 -c 2 _vet-C 'let _par++'
This way, it works and 'ç' or 'Ç' or '09' is ignored.

So, looks like bash does not understand when my command, to the -C option, ends 
and executes passing my array's value to the let builtin.

It shouldn't be this way, I think and according to the bash reference.
Even if I put the '-c' option after "-C 'let _par++'" and the array's name in 
the end, doesn't work.

The sequence of events:
mapfile -t -n 4 -c 2 -C let _par++ _vet
<first value>
<second value><if 'ç' or '09', error>
./test.sh: linha 8: let: ç: erro de sintaxe: operando esperado (token com erro 
é "ç")
<third value><nothing happens>
<fourth value><an error occurs only if the value is 'Ç' or '09'>
./test.sh: linha 8: let: ç: erro de sintaxe: operando esperado (token com erro 
é "ç")
<fifth value><blank line = <enter>>

The source of test.sh:
#! /bin/bash
declare -a _vet
declare -i _par=0
function examp(){
    mapfile -t -n 4 -C (let _par++) -c 2 _vet
    return
}
function array_read(){
    local noi
    for(( noi=0 ; noi < ${#_vet[*]} ; noi++ ))
    do
        printf "${_vet[$noi]}."
    done
    printf "\n\n"
    return
}
examp ; array_read

# something simple to test bash' builtin mapfile - with is really cool, 
ignoring this problem.

Can you, please, tell me if it's not a problem/bug, if it's my fault, so I can 
move on with my learning? Doesn't need say which is my error, just say that I'm 
wrong, that's enough... :)
Thank you

.pi


reply via email to

[Prev in Thread] Current Thread [Next in Thread]