Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #16472
| Path | csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail |
|---|---|
| From | worley@alum.mit.edu (Dale R. Worley) |
| Newsgroups | gnu.bash.bug |
| Subject | An xtrace variant |
| Date | Sun, 28 Jun 2020 15:19:27 -0400 |
| Lines | 125 |
| Approved | bug-bash@gnu.org |
| Message-ID | <mailman.584.1593371976.2574.bug-bash@gnu.org> (permalink) |
| References | <87h7uv0zi8.fsf@hobgoblin.ariadne.com> |
| NNTP-Posting-Host | lists.gnu.org |
| X-Trace | usenet.stanford.edu 1593371977 1749 209.51.188.17 (28 Jun 2020 19:19:37 GMT) |
| X-Complaints-To | action@cs.stanford.edu |
| To | bug-bash@gnu.org |
| Envelope-to | bug-bash@gnu.org |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcastmailservice.net; s=20180828_2048; t=1593371969; bh=ebjv5oi5zPpbA1QqRXFB+ccmYXEBhnjJdmEl0lmJoEo=; h=Received:Received:Received:Received:Received:From:To:Subject:Date: Message-ID; b=Nf0IObBYgq0r03Ym/PKtA75bza3v8Jbi2FnRzbQd/gVAAtkRc7N2x1Q+HSXUgC2/A lcI0Cbp07wH9qEEHuwt+g1d5TDxtpkQTsAUiqwUonokdV5RNlWFff0a4k6gpifkxkN 8ifOvDQkU0WYzA6PQyNdAkjNBWGC0520smMrg7u/XqVqlX+GSNdGmxET7Atw3CoixP PGr1y0+ChF3Fc+RN5VmHF+WVT0EN7l8X8gNSJxV8fIN64zf9k0cqMvj5dep0QDjSWP /hG0Rfe/JN02K0PPx1nTGtK4m98+jS6t+GfiYqZcov5eBt/ZQvZrCTmNSlnUP1Eshw VkSazGO+jcGFA== |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcastmailservice.net; s=20180828_2048; t=1593371969; bh=ebjv5oi5zPpbA1QqRXFB+ccmYXEBhnjJdmEl0lmJoEo=; h=Received:Received:Received:Received:From:To:Subject:Date: Message-ID; b=In9XREMjwFlFy6TCgLyEWXdhWvC6v2kIOXSERwdBOqVnwF5/fqdQ2m+t1NgJ5mRHe DR/ulmigalcDTo7xOs8UOdZjH0DcvpOsJUu+EcFaHkIi7eK8qxupVtIXsdhoNdyrBS ssofoE67InoYUDe/jm6bSwYHhLmc3wL6oAjcUgpiuyoXeVirhbvrZiOq7/dybXnc0U 0Pszp3vnwZM7V2rwO8mAAlQTwSonnpnICNM9K3tLNTQkYkMnUC69Tp9MLQNWC8HgXY nNIxSvBgDNqMHmeQWiE0Pu8wVidUSyUqbL8VFFlS+sK1Pp6gcK7MlpCuBUq/suB4Y2 Eh2T1/NSuFZ8g== |
| X-Xfinity-VMeta | sc=0.00;st=legit |
| X-Authentication-Warning | hobgoblin.ariadne.com: worley set sender to worley@alum.mit.edu using -f |
| Received-SPF | softfail client-ip=2001:558:fe21:29:69:252:207:81; envelope-from=worley@alum.mit.edu; helo=resdmta-ch2-01v.sys.comcast.net |
| X-detected-operating-system | by eggs.gnu.org: First seen = 2020/06/28 15:19:29 |
| X-ACL-Warn | Detected OS = ??? |
| X-Spam_score_int | -11 |
| X-Spam_score | -1.2 |
| X-Spam_bar | - |
| X-Spam_report | (-1.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN |
| X-Spam_action | no action |
| X-BeenThere | bug-bash@gnu.org |
| X-Mailman-Version | 2.1.23 |
| Precedence | list |
| List-Id | Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org> |
| List-Unsubscribe | <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe> |
| List-Archive | <https://lists.gnu.org/archive/html/bug-bash> |
| List-Post | <mailto:bug-bash@gnu.org> |
| List-Help | <mailto:bug-bash-request@gnu.org?subject=help> |
| List-Subscribe | <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe> |
| X-Mailman-Original-Message-ID | <87h7uv0zi8.fsf@hobgoblin.ariadne.com> |
| Xref | csiph.com gnu.bash.bug:16472 |
Show key headers only | View raw
When debugging a shell script, a useful command is:
bash -x script-name
The deficiency of this is that "-x" causes all simple commands in your
startup files to be echoed as they are executed, and often this output
is a lot longer than the output from the commands in the script.
For a long time, I've wanted a variant of -x that only echoed the simple
commands after bash is done executing the startup files. I finally did
a test implementation, naming a new switch "-X". If it is set at the
end of the execution of the startup files, then bash sets "-x", which
causes subsequent simple commands to be echoed.
I named the new option "-X" as a mnemonic variant of "-x". Its long
name is "Xtrace", because I couldn't think of anything better. The code
changes are quite simple really.
Is this a useful idea? Is there a better way to get an effect like
this?
Dale
diff --git a/builtins/set.def b/builtins/set.def
index d2bba43..e71c58f 100644
--- a/builtins/set.def
+++ b/builtins/set.def
@@ -114,6 +114,7 @@ Options:
vi use a vi-style line editing interface
#endif /* READLINE */
xtrace same as -x
+ Xtrace same as -X
-p Turned on whenever the real and effective user ids do not match.
Disables processing of the $ENV file and importing of shell
functions. Turning this option off causes the effective uid and
@@ -122,6 +123,7 @@ Options:
-u Treat unset variables as an error when substituting.
-v Print shell input lines as they are read.
-x Print commands and their arguments as they are executed.
+ -X Set -x after startup files are executed.
#if defined (BRACE_EXPANSION)
-B the shell will perform brace expansion
#endif /* BRACE_EXPANSION */
@@ -231,6 +233,7 @@ const struct {
{ "vi", '\0', (int *)NULL, set_edit_mode, get_edit_mode },
#endif
{ "xtrace", 'x', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
+ { "Xtrace", 'X', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
{(char *)NULL, 0 , (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
};
diff --git a/flags.c b/flags.c
index 6e20841..0828f78 100644
--- a/flags.c
+++ b/flags.c
@@ -159,6 +159,9 @@ int error_trace_mode = 0;
with a 0 status, the status of the pipeline is 0. */
int pipefail_opt = 0;
+/* Non-zero means set -x after startup files are executed. */
+int echo_commands_after_startup = 0;
+
/* **************************************************************** */
/* */
/* The Flags ALIST. */
@@ -187,7 +190,7 @@ const struct flags_alist shell_flags[] = {
{ 't', &just_one_command },
{ 'u', &unbound_vars_is_error },
{ 'v', &verbose_flag },
- { 'x', &echo_command_at_execute },
+ { 'x', &echo_command_at_execute },
/* New flags that control non-standard things. */
#if 0
@@ -204,6 +207,7 @@ const struct flags_alist shell_flags[] = {
{ 'I', &no_invisible_vars },
{ 'P', &no_symbolic_links },
{ 'T', &function_trace_mode },
+ { 'X', &echo_commands_after_startup },
{0, (int *)NULL}
};
diff --git a/flags.h b/flags.h
index fdbf7f9..3b6fa8c 100644
--- a/flags.h
+++ b/flags.h
@@ -48,7 +48,8 @@ extern int
echo_command_at_execute, no_invisible_vars, noclobber,
hashing_enabled, forced_interactive, privileged_mode, jobs_m_flag,
asynchronous_notification, interactive_comments, no_symbolic_links,
- function_trace_mode, error_trace_mode, pipefail_opt;
+ function_trace_mode, error_trace_mode, pipefail_opt,
+ echo_commands_after_startup;
/* -c, -s invocation options -- not really flags, but they show up in $- */
extern int want_pending_command, read_from_stdin;
diff --git a/shell.c b/shell.c
index a2b2a55..4c40cd4 100644
--- a/shell.c
+++ b/shell.c
@@ -731,6 +731,10 @@ main (argc, argv, env)
start_debugger ();
#if defined (ONESHOT)
+ if (echo_commands_after_startup) {
+ set_minus_o_option (FLAG_ON, "xtrace");
+ set_shellopts ();
+ }
executing = 1;
run_one_command (command_execution_string);
exit_shell (last_command_exit_value);
@@ -791,6 +795,11 @@ main (argc, argv, env)
read_and_execute:
#endif /* !ONESHOT */
+ if (echo_commands_after_startup) {
+ set_minus_o_option (FLAG_ON, "xtrace");
+ set_shellopts ();
+ }
+
shell_initialized = 1;
if (pretty_print_mode && interactive_shell)
Back to gnu.bash.bug | Previous | Next | Find similar
An xtrace variant worley@alum.mit.edu (Dale R. Worley) - 2020-06-28 15:19 -0400
csiph-web