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
  • 761,203
  • 64
  • 569
  • 643
chaosink
  • 1,329
  • 13
  • 27
  • 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
  • 11,693
  • 6
  • 41
  • 65
2

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

local_config=~"/.local_config"
chepner
  • 497,756
  • 71
  • 530
  • 681
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • 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