Find throw paths must precede expression in script

bash, find, grep, linux, shell

Solution

Aliases don't accept positional parameters. You'll need to use a function.

f () { find . -name "$1" -type f -exec grep -i "$2" '{}' \; ; }

You'll also need to quote some of your arguments.

f '*.php' function

This defers the expansion of the glob so that `find` performs it rather than the shell.

Problem

I am trying to alias find and grep to a line as show below ``` alias f='find . -name $1 -type f -exec grep -i $2 '{}' \;' ``` I intend to run it as ``` f *.php function ``` but when I add this to .bash_profile and run it I am hit with ``` [a@a ~]$ f ss s find: paths must precede expression Usage: find [-H] [-L] [-P] [path...] [expression] ``` How do I resolve this?

Original source