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: Dr. Werner Fink
Subject: Re: Syntax error near unexpected token `newline' within loops
Date: Mon, 24 Apr 2017 14:56:09 +0200
User-agent: Mutt/1.6.2 (2016-07-01)

On Mon, Apr 24, 2017 at 08:44:11AM -0400, Greg Wooledge wrote:
> On Mon, Apr 24, 2017 at 12:59:01PM +0200, werner@suse.de 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))]}"

Yes I know ... nevertheless, the initial code should not trigger an error
... to make it sure, the initial example was given by a user asking me
why this triggers an error, which IMHO it should not.

-- 
  "Having a smoking section in a restaurant is like having
          a peeing section in a swimming pool." -- Edward Burr

Attachment: signature.asc
Description: PGP signature


reply via email to

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