In the bash below I am asking the user for a panel and reading that into bed . Then asking the user for a file and reading that into file1 .Is the grep in bold the correct way to apply the selected panel to the file ? I am getting a syntax error. Thank you
FILESDIR=/home/cmccabe/Desktop/ref/validation/val
PANELDIR=/home/cmccabe/Desktop/ref/validation/panels
PS3="please select a panel: "
cd "$PANELDIR"
select bed in $(ls *.txt)
do [ "$panel" != "" ] && break
done
PS3="please select a file to analyze with a panel: "
cd "$FILESDIR"
select file1 in $(ls *.vcf)
do [ "$file1" != "" ] && break
done
printf "FILE is: ${file1} and will be used filtered to ${panel} \n"
read -r -p "Is this correct? [y/N] " response
if [[ $response =~ ^[nN][oO]?$ ]]
then
echo 'please try again' && exit
else
logfile="/home/cmccabe/Desktop/ref/validation/val/process.log"
for f in /home/cmccabe/Desktop/ref/validation/val/$file1 ; do
echo "Start filter creation: $(date) - File: $f"
bname=$(basename $f)
pref=${bname%%_*.vcf}
grep -wFf /home/cmccabe/Desktop/ref/validation/panels/$panel $f >/home/cmccabe/Desktop/ref/validation/filtered/${pref}_filtered.txt
echo "End filder creation: $(date) - File: $f"
done >> "$logfile"
line 32: syntax error: unexpected end of file
If you would indent your code inside for , while , if , and similar constructs, it would be easier to see that you have an if , then , and else with no fi .
FILESDIR=/home/cmccabe/Desktop/ref/validation/val
PANELDIR=/home/cmccabe/Desktop/ref/validation/panels
PS3="please select a panel: "
cd "$PANELDIR"
select bed in $(ls *.txt)
do [ "$bed" != "" ] && break
done
PS3="please select a file to analyze with a panel: "
cd "$FILESDIR"
select file1 in $(ls *.vcf)
do [ "$file1" != "" ] && break
done
printf "FILE is: ${file1} and will be used filtered to ${bed} \n"
read -r -p "Is this correct? [y/N] " response
if [[ $response =~ ^[nN][oO]?$ ]]
then
echo 'please try again' && exit
else
fi
logfile="/home/cmccabe/Desktop/ref/validation/val/process.log"
for f in /home/cmccabe/Desktop/ref/validation/val/$file1 ; do
echo "Start filter creation: $(date) - File: $f"
bname=$(basename $f)
pref=${bname%%_*.txt}
grep -wFf /home/cmccabe/Desktop/ref/validation/panels/$bed $f >/home/cmccabe/Desktop/ref/validation/filtered/${pref}_filtered.txt
echo "End filder creation: $(date) - File: $f"
done >> "$logfile"
syntax error near unexpected token `fi
I have no idea what you are trying to do with this script. So, I don't know if the fi should follow the following assignment statement or follow the following for loop, or whether you just need to remove the empty else before the fi and leave the fi where it is???
then or else in an if construct cannot have empty 'body'.
If you still want to have either a then or an else as stubs with nothing in them, follow this paradigm: