bug-bash
[Top][All Lists]
Advanced

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

Syntax error near unexpected token `newline' within loops


From: werner
Subject: Syntax error near unexpected token `newline' within loops
Date: Mon, 24 Apr 2017 12:59:01 +0200

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc -I/home/abuild/rpmbuild/BUILD/bash-4.4 
-L/home/abuild/rpmbuild/BUILD/bash-4.4/../readline-7.0
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-suse-linux-gnu' 
-DCONF_VENDOR='suse' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
-DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib   -fmessage-length=0 
-grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong 
-funwind-tables -fasynchronous-unwind-tables -g  -D_GNU_SOURCE -DRECYCLES_PIDS 
-Wall -g -Wuninitialized -Wextra -Wno-switch-enum -Wno-unused-variable 
-Wno-unused-parameter -Wno-parentheses -ftree-loop-linear -pipe -DBNC382214=0 
-DIMPORT_FUNCTIONS_DEF=0 -fprofile-use -fprofile-correction
uname output: Linux noether 4.4.57-18.3-default #1 SMP Thu Mar 30 06:39:47 UTC 
2017 (39c8557) x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-suse-linux-gnu

Bash Version: 4.4
Patch Level: 12
Release Status: release

Description:
        Since 4.3 including 4.4 bash shows a bug in loops using nested ((...)), 
$((..)), and $(...)

Repeat-By:
The bash code

        V_NAME=Friday
        for (( INDEX=0; INDEX<$((10-$(expr length $V_NAME))); INDEX++ ))
        do
            echo $INDEX
        done

leads to

        bash: syntax error near unexpected token `newline'

whereas using backticks simply works

        V_NAME=Friday
        for (( INDEX=0; INDEX<$((10-`expr length $V_NAME`)); INDEX++ ))
        do
            echo $INDEX
        done

and yes

        V_NAME=Friday
        for (( INDEX=0; INDEX<$((10-${#V_NAME})) ; INDEX++ ))
        do
            echo $INDEX
        done

does also work, nevertheless using $(...) in the very first example is allowed



reply via email to

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