diff --git a/builtin.cpp b/builtin.cpp index 2f644fbe6..36b8ec7a7 100644 --- a/builtin.cpp +++ b/builtin.cpp @@ -2717,6 +2717,7 @@ static int builtin_contains( parser_t &parser, wchar_t ** argv ) argc = builtin_count_args( argv ); int i; wchar_t *needle; + int index=0; woptind=0; @@ -2727,6 +2728,10 @@ static int builtin_contains( parser_t &parser, wchar_t ** argv ) L"help", no_argument, 0, 'h' } , + { + L"index", no_argument, 0, 'i' + } + , { 0, 0, 0, 0 } @@ -2739,7 +2744,7 @@ static int builtin_contains( parser_t &parser, wchar_t ** argv ) int opt = wgetopt_long( argc, argv, - L"+h", + L"+hi", long_options, &opt_index ); if( opt == -1 ) @@ -2772,6 +2777,9 @@ static int builtin_contains( parser_t &parser, wchar_t ** argv ) builtin_unknown_option( parser, argv[0], argv[woptind-1] ); return STATUS_BUILTIN_ERROR; + case 'i': + index=1; + break; } } @@ -2790,6 +2798,7 @@ static int builtin_contains( parser_t &parser, wchar_t ** argv ) if( !wcscmp( needle, argv[i]) ) { + if ( index ) append_format(stdout_buffer, L"%d\n", i-woptind ); return 0; } } diff --git a/doc_src/contains.txt b/doc_src/contains.txt index 4add8b0e6..46d1bce1b 100644 --- a/doc_src/contains.txt +++ b/doc_src/contains.txt @@ -5,6 +5,7 @@ \subsection contains-description Description +- \c -i or \c --index print the the word index - \c -h or \c --help display this message Test if the set VALUES contains the string KEY. Return status is 0 if