environment variable expansion in bash

2

Bash used to expand environment variables when you hit tab:

cd $PWD

would result in $PWD being expanded. When you hit return, the expanded path would go into your history, which was really useful.

Environment variable expansion has been discussed extensively in this group. I need a solution that works for both Mac and Linux and doesn't have other side effects. So we do not use shopt -s direxpand because this doesn't exist on the Mac.

Let's assume your current working directory is /home/user/foo. Is there an easy way to type:

cd $PWD

and have cd /home/user/foo be placed in the history?

Please note obvious things like cd $PWD or cd `echo $PWD` don't work. The command, not the expansion, is put into the history.

Also, cd $PWD/ doesn't quite work because you have to edit the result. For example, if there is only one file in the directory, it expands out to the full pathname of that file.

It would really be nice if tab expansion worked in bash like the old days, but I understand that is a complex topic.

So I think the basic question is: is there a way to get the expanded value of an environment into your history?

user3016511

Posted 2018-02-25T16:24:54.960

Reputation: 21

1In my Kubuntu: Ctrl+Alt+E before Enter. I cannot confirm Mac equivalent though, so it's just a comment. – Kamil Maciorowski – 2018-02-25T17:55:15.380

How about simply trying cd $pwd in lower case just like that? – Pimp Juice IT – 2018-02-25T20:13:52.997

No takers on this?? – javadba – 2019-06-18T12:31:15.160

No answers