2

Scenario

I have a ProductivityScripts project on GitHub, and when I install Linux (Debian 9), I add this folder to PATH for ease of use.

I.e., I add the following line to ~/.bashrc:

export PATH="~/Dev/ProductivityScripts:$PATH"

It works. I can now run scripts from inside this folder by name from anywhere.

alec@my_host:~$ capsalt
SUCCESS!

However, if I type which capsalt I get no output.

whiching most things works.

alec@my_host:~$ which git
/usr/bin/git

Question

Shouldn't which also track down scripts that are available from locations added to PATH manually? Or is there another reason why this isn't working?

  • What shell, and what OS are you using? – Patrick Feb 6 '18 at 13:32
  • This was bash in Debian Stretch. (The question has been answered, but since it may be relevant for someone else at some point, may as well elaborate.) – Alec Feb 6 '18 at 13:42
  • TMUX isn't a shell. Your shell is something like bash or zsh. – Patrick Feb 6 '18 at 13:43
  • Sorry. Then bash. – Alec Feb 6 '18 at 13:45
5

This is most likely due to ~ not acting as a variable inside double quotes in combination with which not doing its own expansion of the tilde.

Use

PATH="$HOME/Dev/ProductivityScripts:$PATH"

instead. HOME is an environment variable and expands as usual within double quotes. Note also that since PATH is already exported, it does not need to be exported again (through it does not hurt).

More information about tilde: Why doesn't the tilde (~) expand inside double quotes?

See also Why not use "which"? What to use then?

  • Yep, that solved it, thanks! Had no idea about the deal with tilde inside double quotes. Definitely a fact that will inevitably become relevant again and again. – Alec Feb 6 '18 at 13:39
  • @Alec My take on it is to always use $HOME in scripts while using ~ only on the command line if my fingers happens to be tired (and it's not in a double quote). $HOME also has the benefit of being more self-documenting than tilde. – Kusalananda Feb 6 '18 at 13:41
  • You know, I'm pretty sick of the finger-twisting I have to do to get the tilde character on a Norwegian keyboard layout. Since it's normally something you use oñ tõp õf other characters, I have to tap it twice to get ~ on its own. May just use $HOME for simplicity's sake, everywhere. – Alec Feb 6 '18 at 13:44

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.