2 shells in one file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting 2 shells in one file
# 1  
Old 10-29-2014
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
Code:
 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 Smilie.

Code:
 #!/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

# 2  
Old 10-29-2014
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
# 3  
Old 10-29-2014
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.

Quote:
Originally Posted by sea
AFAIK there is no 'goto' in bash, only in assembler and [Q{uick}|Visual] Basic.
And C. Not often used, but sometimes one goto is better than 5 nested something-else's.
This User Gave Thanks to Corona688 For This Post:
# 4  
Old 10-29-2014
Currently I have two different shell files (one that converts files and one annotates).

The conversion shell is:
Code:
 #!/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:
Code:
 #!/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:
Code:
 #!/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:
Code:
 #!/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
Code:
 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 Smilie.
This User Gave Thanks to cmccabe For This Post:
# 5  
Old 10-31-2014
I am going to mark this as solved and start a new thread with a better description (hopefully) Smilie Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Please what are shells?

I mean like this: http://shells.red-pill.eu/ Can anyone explain how this works? I hope my post is not spam. I think its related to linux. Thank you (1 Reply)
Discussion started by: postcd
1 Replies

2. UNIX for Dummies Questions & Answers

Significance of different shells?

I'm taking a LINUX and UNIX class and we are using bash as the shell in terminal. On my mac-book I use zsh only because my professor had a pretty cool start-up file for it. It has benefited me in becoming familiar with different shells. However, I'm having a hard time understanding the purpose... (4 Replies)
Discussion started by: syregnar86
4 Replies

3. UNIX for Dummies Questions & Answers

Shells

Lets say my default shell is bash and then i load up csh and then ksh. How would i exit csh without exiting ksh? so basically i gone from bash > csh > ksh and i wish to close csh (2 Replies)
Discussion started by: Bill Thompson
2 Replies

4. UNIX for Dummies Questions & Answers

shells and scripts

So in UNIX, I understand that there are several different shells you can be in: C, Bourne, Bourne Again, Korn, etc. I also know that you can write scripts for the shells, by assigning it by #!/bin/csh, or sh, etc. If I am working in the csh, do I have to write the script for the csh? Or can it... (1 Reply)
Discussion started by: bjstaff
1 Replies

5. UNIX for Dummies Questions & Answers

The /etc/shells file is missing.

Hi the /etc/shells file is missing on some of development boxes. Is this ok? Where can I find this file? ---------- Post updated at 07:07 AM ---------- Previous update was at 07:07 AM ---------- I have solaris, linux, aix and hpux machines and on all of these machines the /etc/shells file is... (8 Replies)
Discussion started by: manju--
8 Replies

6. Shell Programming and Scripting

find all of the available shells

To find all of the available shells in your system we can use cat /etc/shells but i dont find shells in my system where else i can look for same info?? (4 Replies)
Discussion started by: Deepak Dutt
4 Replies

7. Linux

/etc/shells on /etc/passwd

Hi All, Why does these list (below) doesn't belong to /etc/shells? sync:x:5:0:********************// :/sbin:/bin/sync shutdown:x:6:0:********************// :/sbin:/sbin/shutdown halt:x:7:0:********************// :/sbin:/sbin/halt webalizer:x:68:68:***************// ... (2 Replies)
Discussion started by: itik
2 Replies

8. UNIX for Advanced & Expert Users

why we have different shells?

Can you pls. tell me, why we have different shells in UNIX OS ( Eg. SunOs) and also I would like to know what is the specific difference b/w SVR and BSD ? Thanks. (2 Replies)
Discussion started by: shahnazurs
2 Replies

9. Linux

Version of Shells?

Can anyone tell me the version of shells for bash mc pdksh tcsh zsh For Red Hat Enterprise 4? Thank you very much! (2 Replies)
Discussion started by: Xplore
2 Replies

10. UNIX for Advanced & Expert Users

Shells

I have came across the definitions of these shells korn bourne c etc .. but honestly till now i din't get the exact difference between these threes , the advantages ..... can anyone pinpoint me where it actually lies ..... don;t include me answers like aliasing in c is posible and not in bourne ..... (3 Replies)
Discussion started by: dino_leix
3 Replies
Login or Register to Ask a Question