Code exits before completing

The lines in bold check the value of a user input, if it is not one of the expected genes (GJB2, MECP2, PHOX2B), the user is shown a list of formats to use and the variant is entered. It is then supposed to printf that entered variant? Thank you :).

name() {
	printf "\n\n"
	printf "Please enter the gene name  : "; read gene
	
	[ -z "$gene" ] &&
		printf "\n No ID supplied. Leaving match function." &&
		sleep 2 &&
		return
	[ "$gene" = "end" ] &&
		printf "\n Leaving match function." &&
		sleep 2 &&
		exit
	[ "$gene" != "GJB2 or MECP2 or PHOX2B" ] &&
		printf "\n That is not a target gene please use one of the formats listed." &&
		echo "
NM_003002.3:c.274G>T (reference transcript:coding change w/ nucleotide change)
chr11:g.111959693G>T (chromosome:genomic position w/ nucleotide change)
NC_000011.9:g.111959693G>T (Genebank accession #:genomic position w/ nucleotide change)"
	printf "Enter variant(s): "; IFS="," read -a variants

	code=""
	if [ "$gene" = "GJB2" ]
	then	code="NM_004004.5"
	elif [ "$gene" = "MECP2" ]
	then	code="NM_004992.3"
	elif [ "$gene" = "Phox2B" ]
	then	code="NM_003924.3"
	else	return
	fi
	for ((i = 0; i < ${#variants[@]}; i++))
	do	printf "%s:%s\n" "$code" "${variants[$i]}"
	done | tee -a c:/Users/cmccabe/Desktop/Python27/$gene.txt \
			>> c:/Users/cmccabe/Desktop/Python27/out.txt
} 

added code here

Will a 3rd elif added to print this input be ok (at the end) ?

 
code=""
	if [ "$gene" != "GJB2 or MECP2 or PHOX2B" ]
	then	code=printif ((i = 0; i < ${#variants[@]}; i++))
	                tee -a c:/Users/cmccabe/Desktop/Python27/$gene.txt \
			         >> c:/Users/cmccabe/Desktop/Python27/out.txt

You should try to be consistent when using printf , use always same format.
Return IFS to old value, it is good practice so you don't get surprises in code later on.

As the volume of elifs increases the code will be harder to maintain with a higher margin for error.

Use case perhaps ?

case $gene in
	GJB2)
		code="NM_004004.5"
	;;
	MECP2)
		code="NM_004992.3"
	;;
	Phox2B)
		code="NM_003924.3"
	;;
	*) # everything else we do not won't to process.
		printf "%s \n" "This is not a target ..."
	;;
esac
printf "%s \n" "Enter variant(s): "
OLDIFS=$IFS
IFS=","
read -a variants
for (( i = 0; i < ${#variants[@]}; i++ ))
	do
	printf "%s %s\n" "$code" "${variants[$i]}" # is plain redirection ok here instead of using tee ?
	done
IFS=$OLDIFS

If users are providing input to your scripts, i would recommend using getopts and passing those via command line e.g ./myscript -a $gene -b variant1,variant2

Reason is simple, if you ever decide to automate the input (predefined input for all variables) it will be simple, opposing to using approach you are using now.

Hope that helps
Regards
Peasant.

Perfect, that works great... Thank you :slight_smile: