On RHEL5.2 (bash 2.3.25) I can cd `pwd`/[TAB] and pwd is substituted into my current working directory, using the output of pwd(1).

How can I achieve the same functionality in Ubuntu 9.10 (bash 4.0.33).

I have read previous questions that refer to backticks as being old and deprciated. I didn't know this. I can understand nesting them can be difficult, and I use ${} is scripts, but I would like to be able to evaluate commands interactively in the shell.

  • That seems broken. TAB is supposed to complete the path/command, NOT perform variable substitution. – psusi May 19 '11 at 14:04
  • Sounds like something RHEL cooked up special for itself, and likely restricted to pwd. See @Caleb's answer. – djeikyb May 20 '11 at 6:34

This is a feature not a bug.

Think about the scenario this way: In order to make that completion the shell would have to RUN the command in the backticks. This could cause very serious negative consequences if it was something that wasn't meant to run more than once, that took lots of time to execute, etc.

In order to do expansion, bash needs just a string that is a path, not some program to have to execute in order to get a string to complete. Consider the suggestion to use ./ as path for the present working directory as well advised!

Backticks are not old or deprecated, although the newer $() syntax is generally preferred these days. However in your example, using a command at all is ill-advised. Backticks and command should be used sparingly and only when another syntax isn't possible.

| improve this answer | |


cd ./TAB


cd $VAR/...
cd $(cmd)/...

don't work for me, either. Maybe you can compare the /etc/bash_completion files.

| improve this answer | |
  • ./ is a good suggestion, that is the proper way to reference the present working directory. Don't expect $var or $(cmd) expansion to happen on tab, that would actually cause all kinds of other problems. – Caleb May 20 '11 at 5:43

There are situations where "$PWD/" is needed instead of "./", so it should not be suggested to always to use "./" instead of "$PWD/". One example is when you do a symbolic link.

Suppose you're in /somefolder. Now you run the following command:

ln -s ./file /target/file

This becomes a broken link. What you really need to do is:

ln -s $PWD/file /target/file

It is very inefficient to type the whole path. This problem is independent from "deprecation" issues as symlink just doesn't work in this way. Thus, I suggest you to file a bug to fix this problem.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.