Yes or No selection within bash function

I need to add a selection within the bash function below and am having some trouble doing so.

phox2b() {
    printf "\n\n"
    printf "What is the id of the patient getting Phox2B analysis  : "; read id
    printf "Is this an intronic variant?  Y/N "; read match_choice

    case "$match_choice" in
        [yY]) id="${id}"; 
         printf "%s \n" "Please enter variant(s), use a comma between multiple: "
OLDIFS=$IFS
IFS=","
read -a variants
for (( i = 0; i < ${#variants[@]}; i++ ))
	do
	printf "NM_003924.3:%s\n" "${variants[$i]}" >> c:/Users/cmccabe/Desktop/Python27/out.txt
	done
IFS=$OLDIFS

        [nN]) id="${id}";  
	printf "Please enter the coding variant the following is an example"
	echo " c.274G>T"
	
        printf "variant(s), use a comma between multiple: "; IFS="," read -a variant
        
        [ -z "$id" ] && printf "\n No ID supplied. Leaving match function." && sleep 2 && return
        [ "$id" = "end" ] && printf "\n Leaving match function." && sleep 2 && return

        for ((i=0; i<${#variant[@]}; i++))
              do printf "NM_003924.3:%s\n" ${variant[$i]} >> c:/Users/cmccabe/Desktop/Python27/out.txt
        done
	add2text ${id}.txt
	additional
} 

The case syntax:

case "$var" in
   pattern1)
        do something here
	;; # this is important to have
   pattern2)
        do something here
        do something more if wanted
        ;; # this is important to have
   cache_all)
        do something here
        ;; # this is important to have
esac # closing the case and it is not optional 

If you could elaborate, at least, how is failing for you, that might help even more.

for ((i=0; i<${#variant[@]}; i++))
              do printf "NM_003924.3:%s\n" ${variant[$i]} >> c:/Users/cmccabe/Desktop/Python27/out.txt

This will eliminate the indexing.

for v in ${variant[@]}; do
        #do something with "${v}"
1 Like

Why don't you give ANY hint regarding the problem? On third sight - first and second failed! - I can't find the esac statement nor the necessary ;; for the case construct.

What - besides it's extremely messy - is the problem with that code?

1 Like

I apologize for my hasty post... I was in the middle of a problem that is no longer an issue. Anyway, what was failing was the syntax of how the bash was written. I will try again, using the suggestions and post the results. Btw, I have been trying to find tutorials or books on how to write code more clearly/readable, do you have any sugesstions? Thank you :).

Read posts in these forums and compare readable to unreadable ones.

Google style I think is worth having a read. Look at formatting.