hmood
hmood

Reputation: 603

syntax error near unexpected token `if' in Bash Scripting

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'

Upvotes: 0

Views: 445

Answers (1)

Dudi Boy
Dudi Boy

Reputation: 4865

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

Upvotes: 1

Related Questions