0

I am adding an alias to search for a file for a string that leads to me a snippet.

alias snippets="find /oneDrive/Work/Snippets -type f -exec grep -Hi $1 '{}' + "

And calling as

snippets "target"

And getting error as

find: target: unknown primary or operator

Any help greatly appreciated.

Raja G
  • 5,937
  • 1
  • positional arguments like $1 don't work in aliases. 2. even if $1 worked, it would be expanded when the alias is defined (because it's within "..."), not when it's used. 3. use a function instead of an alias: snippets(){ find /oneDrive/Work/Snippets -type f -exec grep -Hi "$1" {} +; }
  • –  Mar 05 '20 at 14:56
  • 1
    Everything said above, better to use a function. But no need for find, grep has recursive mode using -r. – pLumo Mar 05 '20 at 15:02