From de741677d3b0db204d26d93a9b20bd716e2150c6 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Fri, 14 Aug 2026 12:36:49 +0900 Subject: [PATCH] feat: show lineno on error also in interactive shells --- builtins/common.c | 2 ++ config-bot.h | 2 ++ error.c | 6 ++++++ 3 files changed, 10 insertions(+) diff --git a/builtins/common.c b/builtins/common.c index a781a0fa..333fdb15 100644 --- a/builtins/common.c +++ b/builtins/common.c @@ -87,7 +87,9 @@ builtin_error_prolog (void) name = get_name_for_error (); fprintf (stderr, "%s: ", name); +#ifndef INTERACTIVE_SHELL_PRINT_LINENO if (interactive_shell == 0) +#endif fprintf (stderr, _("line %d: "), executing_line_number ()); if (this_command_name && *this_command_name) diff --git a/config-bot.h b/config-bot.h index 07e910f1..ca0aec96 100644 --- a/config-bot.h +++ b/config-bot.h @@ -194,3 +194,5 @@ /* If you don't want bash to provide a default mail file to check. */ /* #undef DEFAULT_MAIL_DIRECTORY */ + +#define INTERACTIVE_SHELL_PRINT_LINENO diff --git a/error.c b/error.c index 10af0709..85a3224e 100644 --- a/error.c +++ b/error.c @@ -77,7 +77,11 @@ error_prolog (int print_lineno) int line; ename = get_name_for_error (); +#ifdef INTERACTIVE_SHELL_PRINT_LINENO + line = print_lineno ? executing_line_number () : -1; +#else line = (print_lineno && interactive_shell == 0) ? executing_line_number () : -1; +#endif if (line > 0) fprintf (stderr, "%s:%s%d: ", ename, gnu_error_format ? "" : _(" line "), line); @@ -96,7 +100,9 @@ get_name_for_error (void) #endif name = (char *)NULL; +#ifndef INTERACTIVE_SHELL_PRINT_LINENO if (interactive_shell == 0) +#endif { #if defined (ARRAY_VARS) bash_source_v = find_variable ("BASH_SOURCE");