(xpost from Unix Stack Exchange)
I'm using a local shell via an Emacs shell buffer. Seemingly at random, my shell will start echoing back every command I type before the rest of the output.
h ~ $ pwd
pwd
/Users/ericauld
h ~ $ echo $-
echo $-
himBCH
h ~ $ bash --version
bash --version
GNU bash, version 5.2.21(1)-release (aarch64-apple-darwin23.0.0)
h ~ $ trap
trap
Notice that neither xtrace (-x) or verbose (-v) are set.
Often I can get it to stop by restarting the shell.
h ~ $ pwd
pwd
/Users/ericauld
h ~ $ exit
exit
exit
Process shell<1> finished
h ~ $ pwd
/Users/ericauld
h ~ $
I notice there are two echoed exits above, which could be a clue.
It seems to happen often, but not always, after I enter and exit a pdb session.
stty -aand check theechopart: in the case where the commands are echoed, that appears in thestty -aoutput asecho; in the case where they are not echoed, it appears as-echo. You can switch from one to the other withstty echoandstty -echo. Doman sttyfor (a lot of) details. I don't know why your shell starts with theechosetting on` sometimes.