По сути, это общая синтаксическая ошибка, не связанная конкретно с токеном ls
. bash
использует парсер yacc, который вызывает обычный yyerror()
при любой проблеме, В рамках полученной обработки ошибок он переходит к попытке определить ошибку. Сообщение приходит из этого куска (см. source):
/* If the line of input we're reading is not null, try to find the
objectionable token. First, try to figure out what token the
parser's complaining about by looking at current_token. */
if (current_token != 0 && EOF_Reached == 0 && (msg = error_token_from_token (current_token)))
{
if (ansic_shouldquote (msg))
{
p = ansic_quote (msg, 0, NULL);
free (msg);
msg = p;
}
parser_error (line_number, _("syntax error near unexpected token `%s'"), msg);
free (msg);
if (interactive == 0)
print_offending_line ();
last_command_exit_value = parse_and_execute_level ? EX_BADSYNTAX : EX_BADUSAGE;
return;
}
Другими словами, он уже сбит с толку '(''
, и, поискав контекст, сообщает ls
.
(
будет законным в начале команды, но не встроенным. На странице руководства:
Compound Commands
A compound command is one of the following:
(list) list is executed in a subshell environment (see COMMAND EXECU‐
TION ENVIRONMENT below). Variable assignments and builtin com‐
mands that affect the shell's environment do not remain in
effect after the command completes. The return status is the
exit status of list.
Дальнейшее чтение: