2

Is there an undocumented PS variable like PS2 that bash would show when it replaces a word designator into its actual value? I think it would help clarify where the command ends and where the execution begins.

Example: I run an ls and a cat. cat uses the last argument of the previous command with a word designator, !$. bash replaces the word designator with the actual value in a new line and then will output the command:

> ll .bash_profile
-rw-r--r--. 1 ec2-user ec2-user 176 Dec 22  2015 .bash_profile
> cat !$
cat .bash_profile
# .bash_profile

# Get the aliases and functions
[...]

To make it clearer, what I ask for is a variable that would insert a text before the replacement takes place, something like

> export MISSING_VARIABLE='--->'
> ll .bash_profile
-rw-r--r--. 1 ec2-user ec2-user 176 Dec 22  2015 .bash_profile
> cat !$
--->cat .bash_profile
[...]
Juanma
  • 132
  • 8
  • 2
    I don't think it is quite what you're asking, but running starting bash with the `-x` option or after `set -x` bash will print the full commands as they are executed and that will usually show all expansions and substitutions that occur. – HBruijn Jul 30 '19 at 15:06

1 Answers1

2

You can ask to bash to show you each expanded command before it is executed by setting

shopt -s histverify

or you can use the readline function shell-expand-line, which I think is bound by default to Meta Control E to expand what you have typed so far. The man page says

This performs alias and history expansion as well as all of the shell word expansions.

meuh
  • 1,288
  • 9
  • 11
  • `histverify` is more or less what I wanted but requires you to hit enter again... – Juanma Jul 31 '19 at 07:41
  • 1
    @JuanClavero `readline` (the lib that processes the input from an interactive bash command line) has a command, `magic-space`, that will do history expansion before you hit enter. It's not bound to a key by default. One way to bind it is to put this in your .inputrc file: `Space: magic-space`. (You can bind whatever key you want...`` is usually a good choice, though.) Then, for example, you can enter `blah blah !$` and hit `` and the `!$` will be expanded. – B Layer Nov 24 '19 at 03:38