Attempting to locate all lines in a list of files containing jane
, then test if the result exists as a real file, and append their names to a Document. Here is my code:
#!/bin/bash
> oldFiles.txt
janeSearch=$( grep " jane " ../data/list.txt | cut -d ' ' -f 1,3 )
for x in $janeSearch;
if test -e ~/$x: then
echo $x >> oldFiles.txt
fi
Can someone explain why I get the following error?
syntax error near unexpected token `if'
CodePudding user response:
Suggesting to try the following
#!/bin/bash
oldFiles.txt
janeSearch=$( grep " jane " ../data/list.txt | cut -d ' ' -f 1,3 )
for x in $janeSearch; if (test -e ~/$x); then echo $x >> oldFiles.txt fi done