Grabbing value from file and run command in ``

Hi ALL,

How can I make a script take data from a file and execute the commands within `` in the file n put that that in a variable?

for i in `cat file`
do
    file=`grep -i key file`
    cp ${file} test
done

file
/tmp/`date +y`log
/tmp/unix`date +y`log

Using `` is 'old', use $() instead.

Your for loop copies the file you cat'ed output of 'file', defines the variable file by greping file (which you already cat'ed), and then copy file (which you cat'ed) as many times as entries are found in file (which you cat'ed) to test, overwrite 'test' as many times as entries were found.

Then you execute 3 files..
1) the file you cat'ed
2) and /tmp/[unix)$(date +y)log

for ENTRY in $(cat /some/file)
do
    workfile=$(grep -i key $ENTRY)
    cp ${workfile} test.$ENTRY
done

Assuming /some/file holds a list of diffrent files....
Now it sets the variable workfile to the content of the result of grep'ing key out of $ENTRY, and then copies the $workfile to the current path test.$ENTRY, where $ENTRY is the filename (if the (some/file contains other filenames/paths) of the file you grep'ed ALL lines containing the word 'key' in it.
At least it doesnt overwrite the file 'test' a dozen times anymore...

Can you elaborate a bit more of what you'd like to achieve?
For example with the logfiles and by the call of the 'file'?

EDIT:
Been late, of course, if test is a directory, all files are copied there.