2

I want to do things like this:

local_config="~/.local_config"
source $local_config

But it seems that the string is not treated as a file path.

I'm using Zsh.

anubhava
  • 713,503
  • 59
  • 514
  • 593
chaosink
  • 1,208
  • 12
  • 25
  • Keep `~` outside quotes to make it: `local_config=~"/.local_config"` – anubhava May 02 '18 at 20:07
  • Yes. That works! It is unexpected that Nobody asked this question. – chaosink May 02 '18 at 20:24
  • Possible duplicate of [Tilde expansion in quotes](https://stackoverflow.com/questions/15858766/tilde-expansion-in-quotes) – chepner May 03 '18 at 19:36
  • 1
    There are various `bash` questions, and I (prematurely) voted to close this as a duplicate of one of them, but `zsh` does behave differently enough to warrant leaving this open. – chepner May 03 '18 at 19:39

2 Answers2

2

Try without quotes:

local_config=~/.local_config

or

local_config="$HOME/.local_config"
Harald Nordgren
  • 10,644
  • 6
  • 39
  • 60
2

~ is not expanded inside the single or double quotes. To make it work, keep ~ outside the quotes as:

local_config=~"/.local_config"
chepner
  • 446,329
  • 63
  • 468
  • 610
anubhava
  • 713,503
  • 59
  • 514
  • 593
  • 1
    Sorry I edited the answer; I missed the `zsh` tag, and `zsh` is more forgiving than `bash` is regarding tilde expansion. – chepner May 03 '18 at 19:37