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?

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
Alec
  • 507

1 Answers1

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?

Kusalananda
  • 333,661
  • 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 06 '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 06 '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 06 '18 at 13:44