0

This is zsh but perhaps applies to other shells.

Say you are in directory /foo and you

% find $PWD -name '.*'

it works fine, results are from /foo.

Now (in /foo) type this

% alias crazy="find $PWD -name '.*'"

Now go % crazy and you'll see the same result. All good.

But. Say in (example) Mac, put in your .zshrc

# Let's see what happens:
% alias crazy="find $PWD -name '.*'"

Now, for example on the Mac, open a new Terminal session. In the Mac *nix case, it does that, opening the zsh in some particular default directory, in fact /blah/fattie .

Now % cd /foo and enter crazy

In fact. The results you get are the results from /blah/fattie .

If you want "crazy" to work as expected, you have to, essentially, do this

% alias crazy="find $PWD -name '.*'"

again in /foo and then it will operate on "that" directory ie /foo

Is there a solution to make

% alias crazy="find $PWD -name '.*'"

work in the "directory it is in now" rather than "the directory it was in when the alias was made"?

Fattie
  • 229

1 Answers1

0

Ah, the solution is simple, thanks to use Kamil

Wrong

% alias crazy="find $PWD -name '.*'"

Correct:

% alias crazy="find \$PWD -name '.*'"
Fattie
  • 229