0

I have added the following alias to my .zshrc:

alias pwdc="echo -n $PWD | xclip -selection clipboard"

it seems the present working directory is not getting updated, when I move to a different directory. I have tried this too:

alias pwdc="echo -n `pwd` | xclip -selection clipboard"

Can somebody please explain me what am I doing wrong? any suggestion will be helpful, thank you!

muru
  • 72,889

1 Answers1

3

Variables in double quotes are expanded immediately, so you need to single quote the command (or at least the part with the variable):

$ alias cc='echo "$PWD"'
$ cd "$(mktemp --directory)"
$ cc
/tmp/tmp.9OuF0ZAE1b

In any case, using a function instead avoids such issues.

l0b0
  • 51,350