I'm not clear what you are trying to achieve/searching for. Maybe if you elaborate what exactly are you trying to do and what the AND is supposed to do we could help more.
This solution executes from vim command:
grep PATTERN /some/path/*
If you are looking for files in a directory you would use:
ls /some/path | grep PATTERN
You can update relevant pieces of the command.
Anyway...
From your script I assume you have a line specifying path to a directory which you want to grep for something, e.g. you want to search path for PATTERN, you position cursor on the line with path, then you want to extract the path and grep it for the pattern with your command, example line in file:
source /some/path
This command should do what you expect:
:command! -nargs=1 GrepSource :exe printf("!grep '<args>' '%s'/*", substitute(
getline('.'), "\\%(source\\s*\\)\\(.*\\)$", "\\1",""))
With cursor on the line with path starting with word source you can execute the above command:
:GrepSource PATTERN
This will search files in '/some/path/' for word PATTERN.
I assume paths in your file don't end with slash '/' and I assume you want to search in files so I append '/*' at the end of path to search, ending with command:
grep PATTER /some/path/*
I have used substitute
command that replaces
source /some/path
with
/some/path
Which is then used in printf
to create the actual command.