Home > database >  Using fish shell builtins with find exec
Using fish shell builtins with find exec

Time:06-08

I'm trying to source a file that I can get from the output of find using these commands:

find ./ -iname activate.fish -exec source {} \;

and

find ./ -iname activate.fish -exec builtin source {} \;

But both these commands give the error of the form find: ‘source’: No such file or directory or find: ‘builtin’: No such file or directory. Seems like exec of find is not able to recognize fish's builtins ?

What I basically want to achieve is a single command that will search for Python's virtualenv activate scripts in the current directory and execute them.

So doing something like -exec fish -c 'source {}; \ would not help. I've tried it as well and it doesn't error out but does not make the changes either.

Any ideas what can be done for this ?

Thanks!

CodePudding user response:

As mentioned in comments, seems like -exec does not run in or affect the current shell environment. So find -exec is not gonna work for my use case.

Instead, this will work:

source (find ./ -iname activate.fish)

CodePudding user response:

Perhaps you need:

for file in (find ./ -iname activate.fish)
  source $file
end

# or
find ./ -iname activate.fish | while read file
  source $file
end

Command substitution executes the command, splits on newlines, and returns that list.

  • Related