I was playing around with the readline functions
From the documentation:
shell-expand-line Expand the line as the shell does. This performs alias and history expansion as well as all of the shell word expansions (see Shell Expansions).
My understanding of this is that
shell-expand-line would perform all substitutions and expansions that bash would before the point of actual execution.
A contrived example seems to support this:
$ NAME="Adam" $ alias ec='echo' $ ec $NAME
If I execute the function
shell-expand-line the previous command expands to
$ echo Adam.
Where my confusion begins is with the following example:
$ alias cdspace='cd ~/path\ with\ spaces' $ cdspace
Based on my understanding if I were to execute
shell-expand-line the command would expand to
$ cd /Users/Adam/path\ with\ spaces. However in practice it expands to
$ cd ~/path with spaces. Executing
cdspace either as is, or with
alias-expand-line works as expected, however if I expand it with
shell-expand-line execution fails.
After the preceding expansions, all unquoted occurrences of the characters ‘\’, ‘'’, and ‘"’ that did not result from one of the above expansions are removed.
So it seems like unquoted backslashes are always removed. To test this, if I manually type
$ cd ~/path\ with\ spaces and then execute
shell-expand-line it updates the command to
$ cd ~/path with spaces. Furthermore, if I type
$ cd ~/path\\ with\\ spaces and then execute
shell-expand-line twice each execution it removes one set of of back slashes.
My expectation is that
shell-expand-line fully expands the line to what would be ultimately resolved by bash internally, but this does not seem to be the case as it needs to be executed multiple times.
Where I am ultimately confused now is how
$ cd ~/path\ with\ spaces correctly executes as by my understanding of the Shell Expansions documentation, it will eventually be resolved to
$ cd ~/path with spaces.