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

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,678