Quantcast
Viewing all articles
Browse latest Browse all 2

Answer by Kusalananda for Expand shell variable while editing command line

You may invoke the Readline function shell-expand-line by pressing Meta+Ctrl+e (on my system Meta is Esc) if the bash shell is in Emacs editing mode.

Illustration:

$ echo $PATH

If I now press Meta+Ctrl+e, the shell replaces the whole line with

$ echo /usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin

This would also expand command substitutions and would therefore potentially execute parts of the command line needed for the expansion to occur. It also means that unfinished things like $( would generate a syntax error.

This does not expand shell globbing patterns.

If you want to use this in Vi editing mode, then you will need to explicitly bind the shell-expand-line function to a key sequence as it is not bound by default. For example, to bind it to Ctrl+e, use

bind '"\C-e": shell-expand-line'

Using the same key sequence as in Emacs mode would obviously be problematic as Esc has a special function in Vi mode.


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>