diff --git a/builtin.c b/builtin.c index 7c5267c6a..94ce93999 100644 --- a/builtin.c +++ b/builtin.c @@ -2462,7 +2462,7 @@ static int builtin_for( wchar_t **argv ) else if ( wcsvarname(argv[1]) ) { sb_printf( sb_err, - _( L"%ls: '%ls' is not a valid variable name\n" ), + BUILTIN_FOR_ERR_NAME, argv[0], argv[1] ); builtin_print_help( argv[0], sb_err ); @@ -2521,12 +2521,16 @@ static int builtin_begin( wchar_t **argv ) return proc_get_last_status(); } +/** + Define the function specified by the function_data_t structure. If + the do_save flag is set, also write it out to file. +*/ static void builtin_end_add_function_def( function_data_t *d ) { /** Copy the text from the beginning of the function - until the end command and use as the new definition - for the specified function + until the end command and use as the new definition + for the specified function */ void *context = halloc( 0, 0 ); @@ -3006,7 +3010,8 @@ static int builtin_return( wchar_t **argv ) } /** - Builtin for executing one of several blocks of commands depending on the value of an argument. + Builtin for executing one of several blocks of commands depending + on the value of an argument. */ static int builtin_switch( wchar_t **argv ) { @@ -3036,7 +3041,8 @@ static int builtin_switch( wchar_t **argv ) } /** - Builtin used together with the switch builtin for conditional execution + Builtin used together with the switch builtin for conditional + execution */ static int builtin_case( wchar_t **argv ) { diff --git a/builtin.h b/builtin.h index c8610313d..59959e337 100644 --- a/builtin.h +++ b/builtin.h @@ -67,6 +67,8 @@ enum */ #define BUILTIN_FOR_ERR_COUNT _( L"%ls: Expected at least two arguments, got %d\n") +#define BUILTIN_FOR_ERR_NAME _( L"%ls: '%ls' is not a valid variable name\n" ) + /** Error message when too many arguments are supplied to a builtin */ diff --git a/parser.c b/parser.c index c7088ff4c..e62c28474 100644 --- a/parser.c +++ b/parser.c @@ -3399,7 +3399,28 @@ int parser_test( const wchar_t * buff, */ if( wcscmp( cmd, L"for" ) == 0 ) { - if( arg_count == 2 ) + if( arg_count == 1 ) + { + + if( wcsvarname( tok_last( &tok )) ) + { + + err = 1; + + if( out ) + { + error( SYNTAX_ERROR, + tok_get_pos( &tok ), + BUILTIN_FOR_ERR_NAME, + L"for", + tok_last( &tok ) ); + + print_errors( out, prefix ); + } + } + + } + else if( arg_count == 2 ) { if( wcscmp( tok_last( &tok ), L"in" ) != 0 ) {