2 shells in one file

In the below code I am trying to combine two shell into one, but not sure if Im doing it right. Basically, there are 3 steps:

Step 1: the file conversion (which is underlined and asks the user if the file needs to be converted, if "y", then it runs the perl script if "n" then it skips to line 14

 printf "Is this a batch or sanger analysis :" ; read id 

)

Steps 2 and 3 already seem to work, but are asking the user if it is a batch or individual analysis, and if "y" one perl script is run, if "n" then another user prompt and perl command is run. Thanks :).

 #!/bin/bash
while true
	do
        printf "Does the file need to be converted  : " ; read id
        cd 'C:\Users\cmccabe\Desktop\annovar'
        case "$id" in
        [yY])  perl convert2annovar.pl -includeinfo -format vcf4old ${id}_matched.vcf > ${id}_matched.avinput
		;;
		[nN]) # code for X
		Goto line 14
	done
	    while true
	do
		printf "Is this a batch or sanger analysis :" ; read id
		cd 'C:\Users\cmccabe\Desktop\annovar'
        case "$id" in
        [yY])  perl -ne 'chomp; system ("perl table_annovar.pl $_ humandb/ -buildver hg19 -protocol refGene,popfreq_all,common,clinvar,clinvarsubmit,clinvarreference -operation g,f,f,f,f,f -otherinfo")' < file.txt 
                ;;
        [nN]) # code for X
                printf "Enter ID  : " ; read id
				cd 'C:\Users\cmccabe\Desktop\annovar'
                [ -z "$id" ] && break
                [ "$id" = "end" ] && break
				perl table_annovar.pl ${id}_matched.avinput humandb/ -buildver hg19 -protocol refGene,popfreq_all,common,clinvar,clinvarsubmit,clinvarreference -operation g,f,f,f,f,f -otherinfo
                ;;
        end)  break ;;
        *)     ;; # Unknown option, do nothing
		esac
		Goto line 4
	done

AFAIK there is no 'goto' in bash, only in assembler and [Q{uick}|Visual] Basic.
Also, there is an incomplete (failing), yet unrequired, 'do loop' in the middle.
Furthermore, each case needs a closing esac .

Unless your files are named like: [yYnN]-matched* there will be a filename error.
Try setting another var according to 'id's value, or rename 'id' to 'answer' or alike and then change 'id' as accordingly.

Hope this helps

Could you post a clear description of exactly what your program's supposed to do, please? We've all kind of been working from your original, and I'm no longer sure that's anything resembling what you wanted.

And C. Not often used, but sometimes one goto is better than 5 nested something-else's.

1 Like

Currently I have two different shell files (one that converts files and one annotates).

The conversion shell is:

 #!/bin/bash
while true
do
        printf "Enter ID  : " ; read id
        cd 'C:\Users\cmccabe\Desktop\annovar'
        [ -z "$id" ] && break
        [ "$id" = "end" ] && break
        perl convert2annovar.pl -includeinfo -format vcf4old ${id}_matched.vcf > ${id}_matched.avinput
done 

and allows the user to enter the id of the file to be converted without knowing the code.

The annotation shell:

 #!/bin/bash
	    while true
	do
		printf "Is this a batch or sanger analysis :" ; read id
		cd 'C:\Users\cmccabe\Desktop\annovar'
        case "$id" in
        [yY])  perl -ne 'chomp; system ("perl table_annovar.pl $_ humandb/ -buildver hg19 -protocol refGene,popfreq_all,common,clinvar,clinvarsubmit,clinvarreference -operation g,f,f,f,f,f -otherinfo")' < file.txt 
                ;;
        [nN]) # code for X
                printf "Enter ID  : " ; read id
				cd 'C:\Users\cmccabe\Desktop\annovar'
                [ -z "$id" ] && break
                [ "$id" = "end" ] && break
				perl table_annovar.pl ${id}_matched.avinput humandb/ -buildver hg19 -protocol refGene,popfreq_all,common,clinvar,clinvarsubmit,clinvarreference -operation g,f,f,f,f,f -otherinfo
                ;;
        end)  break ;;
        *)     ;; # Unknown option, do nothing
		esac
		printf "Is this a batch or sanger analysis :"
	done 

allows the user to enter a batch or individual analysis without knowing the code.

---------- Post updated at 12:02 PM ---------- Previous update was at 11:07 AM ----------

Currently I have two different shell files (one that converts files and one annotates).

The conversion shell is:

 #!/bin/bash
      while true
do
        printf "Enter ID  : " ; read id
        cd 'C:\Users\cmccabe\Desktop\annovar'
        [ -z "$id" ] && break
        [ "$id" = "end" ] && break
        perl convert2annovar.pl -includeinfo -format vcf4old ${id}_matched.vcf > ${id}_matched.avinput
done 

and allows the user to enter the id of the file to be converted without knowing the code.

The annotation shell:

 #!/bin/bash
	    while true
	do
		printf "Is this a batch or sanger analysis :" ; read id
		cd 'C:\Users\cmccabe\Desktop\annovar'
        case "$id" in
        [yY])  perl -ne 'chomp; system ("perl table_annovar.pl $_ humandb/ -buildver hg19 -protocol refGene,popfreq_all,common,clinvar,clinvarsubmit,clinvarreference -operation g,f,f,f,f,f -otherinfo")' < file.txt 
                ;;
        [nN]) # code for X
                printf "Enter ID  : " ; read id
				cd 'C:\Users\cmccabe\Desktop\annovar'
                [ -z "$id" ] && break
                [ "$id" = "end" ] && break
				perl table_annovar.pl ${id}_matched.avinput humandb/ -buildver hg19 -protocol refGene,popfreq_all,common,clinvar,clinvarsubmit,clinvarreference -operation g,f,f,f,f,f -otherinfo
                ;;
        end)  break ;;
        *)     ;; # Unknown option, do nothing
		esac
		printf "Is this a batch or sanger analysis :"
	done 

allows the user to enter a batch or individual analysis without knowing the code.

What I am trying to do is combine the two into one shell and based off of user input "y or n" different commands are run.

For example, the user is asked if the file needs to be converted and type "y", so a script associated with a "y" response is run

 perl convert2annovar.pl -includeinfo -format vcf4old ${id}_matched.vcf > ${id}_matched.avinput 

that part of the code loops unless "n" is typed then it skips to line 14. I hope this helps and thank you :).

1 Like

I am going to mark this as solved and start a new thread with a better description (hopefully) :slight_smile: Thanks.