bug-bash
[Top][All Lists]
Advanced

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

Re: Syntax error near unexpected token `newline' within loops


From: Greg Wooledge
Subject: Re: Syntax error near unexpected token `newline' within loops
Date: Mon, 24 Apr 2017 08:44:11 -0400
User-agent: Mutt/1.4.2.3i

On Mon, Apr 24, 2017 at 12:59:01PM +0200, address@hidden wrote:
>       V_NAME=Friday
>       for (( INDEX=0; INDEX<$((10-$(expr length $V_NAME))); INDEX++ ))

The outer (( )) in the C-style for loop already create an arithmetic
expression context.  You don't need to use $(( )) inside them.  You can
simply write:

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

By the way, the [ ] index syntax in an indexed (not associative) array
expansion works the same way.  You can simply write:

"${a[x+1]}"

instead of

"${a[$((x+1))]}"



reply via email to

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