[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Echoing commands
From: |
Dale R. Worley |
Subject: |
Re: Echoing commands |
Date: |
Thu, 13 Jun 2024 11:51:13 -0400 |
Angelo Borsotti <angelo.borsotti@gmail.com> writes:
> the solution to show commands with "set -x" has, however, a flow: it
> does not show properly commands that contain redirections. E.g.,
...
> cat f1.txt f1.txt > f1.tmp
But showing redirections properly is difficult, not just in the
implementation, but in what it *means*: In the context of Posix shells,
indirection is not an aspect of a command but a change in the
environment in which a command executes, and that change is only
*usually* scoped to just one command.
For instance, how should this be logged?
$ { echo foo ; echo bar ; } >/dev/null
+ echo foo
+ echo bar
$
There is only one indirection but it affects two simple commands. The
indirection is established before either command is executed (or even
parsed), and removed afterward.
(Interestingly, I just discovered that "local" environment variable
settings that apply to only one command are logged by set -x:
$ FOO=BAR echo baz
+ FOO=BAR
+ echo baz
baz
$
)
Though that suggests that a possibly useful feature would be to log
redirections as they are established, requiring the user to deduce which
redirections apply to each command. (But the user has to deduce what the
control structures are doing already, so that's not so different from
now.) That might yield something like
$ { echo foo ; echo bar ; } >/dev/null
+ >/dev/null
+ echo foo
+ echo bar
$
Though ironically it would negate this trick:
$ alias @echo-off='{ set +x; } 2>/dev/null'
... activate feature ...
$ @echo-off
+ 2>/dev/null
$
Dale
Re: Echoing commands, Koichi Murase, 2024/06/12
Re: Echoing commands, Robert Elz, 2024/06/13