Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-04-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Location: Aachen, Germany
Posts: 2,034
Thanks: 26
Thanked 462 Times in 447 Posts
For x in a b c; { list; } (in lieu of do list; done) works (in bash) - why and how?

In this post I came across the cited construct. It works! while ... { list; } does not.
man bash does not mention it (or, better, I didn't see it).

Any reason for / behind this? Am I missing something?
Sponsored Links
    #2  
Old 02-04-2013
neutronscott's Avatar
script kiddie
 
Join Date: Jun 2011
Location: Charleston, SC
Posts: 649
Thanks: 18
Thanked 189 Times in 179 Posts
how about f() without braces?


Code:
mute@clt:~$ f() for x in 1 2 3; { echo $x; };
mute@clt:~$ f
1
2
3

implementation. somehow for got away with accepting a list, but while didn't. I would not rely on it, but it has saved me a few bytes with code golfing
Sponsored Links
    #3  
Old 02-04-2013
Scrutinizer's Avatar
Moderator
 
Join Date: Nov 2008
Location: Amsterdam
Posts: 7,812
Thanks: 148
Thanked 1,772 Times in 1,609 Posts
I think this undocumented syntax is still there for historical reasons and should not be used. I noticed it works in both old and new bash versions. It also works in zsh and ksh93, but not in ksh88. It is not POSIX compliant and does not work in dash.
    #4  
Old 02-04-2013
alister alister is offline Forum Advisor  
Registered User
 
Join Date: Dec 2009
Posts: 2,710
Thanks: 130
Thanked 744 Times in 623 Posts
Shells with that type of for-loop support typically also support an analogous select statement: select i in a b c; { echo $i; }

I have never used either myself. I see no benefit, only headaches.

Regards,
Alister
Sponsored Links
    #5  
Old 02-04-2013
Moderator
 
Join Date: Jul 2012
Location: San Jose, CA, USA
Posts: 1,681
Thanks: 72
Thanked 605 Times in 529 Posts
Quote:
Originally Posted by Scrutinizer View Post
I think this undocumented syntax is still there for historical reasons and should not be used. I noticed it works in both old and new bash versions. It also works in zsh and ksh93, but not in ksh88. It is not POSIX compliant and does not work in dash.
To be picky: An application using these features is not a strictly conforming POSIX application, but a shell that provides these features is not made non-compliant by providing this feature as an extension to the standard.

An application could be a POSIX conforming application using extensions if it documented that it needed a shell that supports this syntax and otherwise used only features documented by the POSIX standards.

Otherwise, as far as the standards are concerned, the behavior of an application using syntax that is not documented by the standard is unspecified.
Sponsored Links
    #6  
Old 02-05-2013
Scrutinizer's Avatar
Moderator
 
Join Date: Nov 2008
Location: Amsterdam
Posts: 7,812
Thanks: 148
Thanked 1,772 Times in 1,609 Posts
I like it when you're being picky. With "It is not .." , I meant "The use of these features is not.."
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Take a list if strings from a file and search them in a list of files and report them realspirituals Shell Programming and Scripting 8 10-13-2011 06:37 AM
find list of files from a list and copy to a directory manishabh Shell Programming and Scripting 3 09-13-2009 06:03 PM
Splitting a list @list by space delimiter so i can access it by using $list[0 ..1..2] shriyer Shell Programming and Scripting 1 07-29-2009 02:05 PM
Make a list in bash out of arguments jolecanard Shell Programming and Scripting 4 07-02-2009 04:23 PM
[bash]Stripping lines from a list noratx UNIX for Dummies Questions & Answers 8 04-04-2008 02:38 AM



All times are GMT -4. The time now is 05:21 AM.