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.
$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" {} +; }
find
,grep
has recursive mode using-r
. – pLumo Mar 05 '20 at 15:02