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!

0
2

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.

1

Not the answer you're looking for? Browse other questions tagged or ask your own question.