I am writing a simple script which will take a keyword. Then, it will look for files in the directory which contain that keyword and copy them to another directory (name of directory = keyword).
The keyword is passed as a command line argument. Here's my script:
#!/bin/bash
# start
mkdir $1
cp `grep -Ril \"$1\"` $1
I seem to have an error with the cp command saying:
missing destination file operand
How can I correct this error?
Thanks!
grepfinds nothing?cdcommand.grepfinds nothing, the resultingcp $1command then lacks a destination file, causing the error message. Are you sure that's fine?