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"?

2
  • In your example you could just replace $PWD with ..
    – mpy
    Commented Aug 7, 2022 at 9:06
  • @mpy find behaves subtly differently re dot files in that case unfortunately, hence the issue.
    – Fattie
    Commented Aug 7, 2022 at 13:46

1 Answer 1

0

Ah, the solution is simple, thanks to use Kamil

Wrong

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

Correct:

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

Not the answer you're looking for? Browse other questions tagged .