Bash menu opens and closes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash menu opens and closes
# 1  
Old 03-11-2015
Bash menu opens and closes

Ever since I added these two code blocks to my bash menu it just opens and closes right away. I use a batch file that worked fine until these codes were added and I am not sure what is wrong.

Basically, what I am trying to do in the additional section is if the answer is "Y" then it goes back to the first command (gjb2), but if the answer is "N" then it goes to the annovar section.

After annovar runs the user is prompted again and if the answer is "Y" then it goes back to the menu, but if the answer is "N" then the programs exits. Thank you Smilie.

I attached the full .sh as well. Thank you Smilie

Code:
 additional() {
    printf "\n\n"
    printf "Are there additonal GJB2 patients to be analyzed?  Y/N "; read match_choice

    case "$match_choice" in
        [yY]) id=""; gjb2 ;;
        [nN]) id=""; annovar ;;  
    esac
}

annovar() {
    printf "\n\n"
    printf "How many patients  : "; read id

    [ -z "$id" ] && printf "\n No ID supplied. Leaving match function." && sleep 2 && menu
    [ "$id" = "end" ] && printf "\n Leaving match function." && sleep 2 && menu

    cd 'C:\Users\cmccabe\Desktop\annovar'
              $( 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")' < sanger.txt )
     printf "The annotation is complete, would you like analyze additional patients  : "; read match_choice
	 case "$match_choice" in
        [yY]) id=""; menu ;;
        [nN]) id=""; printf "\n Goodbye! \n\n"; exit ;;
}
# actual start of this program
menu # run menu function

# 2  
Old 03-11-2015
Looks like an esac is missing in the annovar function...
This User Gave Thanks to RudiC For This Post:
# 3  
Old 03-12-2015
Thank you Smilie, it is working now.

---------- Post updated at 09:24 AM ---------- Previous update was at 08:08 AM ----------

Spoke to soon, I added the below lines and the same thing happens, can you please take a look at what I am over-looking? Thank you Smilie.

What is supposed to happen is after the variant is entered by the user it is saved in ${id}.txt and the NameChecker python script is run.
The result of the NameChecker is displayed and the user is asked if the variant is correct, if the answer is "Y" then goto the position function, but if the answer is "N" then goto the gjb2 function and ${id}.txt is cleared. Thank you Smilie.

Code:
 # run python NameChecker
	cd 'C:'
    C:/Users/cmccabe/Desktop/Python27/python.exe C:/Users/cmccabe/Desktop/Python27/run_batch_job.py C:/Users/cmccabe/Desktop/Python27/${id}.txt NameChecker
	
check() {
    printf "\n\n"
    printf "Is the variant correct?  Y/N "; read match_choice

    case "$match_choice" in
        [yY]) id=""; position ;;
        [nN]) id=""; gjb2 ;; echo -n "" > ${id}.txt  
    esac
}

    position() {                  
# run python PositionConverter
    printf "\n\n"
	cd 'C:'
    C:/Users/cmccabe/Desktop/Python27/python.exe C:/Users/cmccabe/Desktop/Python27/run_batch_job.py C:/Users/cmccabe/Desktop/Python27/${id}.txt C:/Users/cmccabe/Desktop/annovar/${id}.txt PositionConverter
    convert
}


Last edited by cmccabe; 03-12-2015 at 01:58 PM..
# 4  
Old 03-12-2015
is ${id} set somewhere outside of the posted code?

Otherwise i dont recall windows shell that good, but i thought to change the disk, you would just enter c:, where to change to C: 's root dir, you would do a cd c:\.
Saying, doing cd C: while beeing (anywhere) on C:, is about the same as in linux cd .

hth
# 5  
Old 03-12-2015
Yes, ${id}.txt is set using the below code which is just outside:

Things worked before I added the new code, but I'm not sure what changed, I will start investigating the directory. Thank you Smilie.

Code:
 gjb2() {
    printf "\n\n"
    printf "What is the id of the patient getting GJB2 analysis  : "; read id
    printf "Enter variant: "; read variant
 
 [ -z "$id" ] && printf "\n No ID supplied. Leaving match function." && sleep 2 && return
    [ "$id" = "end" ] && printf "\n Leaving match function." && sleep 2 && return
 
 # save file in windows python directory
    printf "%s\n" "$variant" > c:/Users/cmccabe/Desktop/Python27/$id.txt
 
 # add transcript
 sed -i '$a NM_004004.5:' c:/Users/cmccabe/Desktop/Python27/$id.txt
    printf "NM_004004.5:%s\n" "$variant" > c:/Users/cmccabe/Desktop/Python27/$id.txt

# 6  
Old 03-12-2015
You clear id and then echo > ${id}.txt ? That will create an empty .txt file...

In general, you do nested / recursive calls to functions (like calling menu from within a function that itself is called by menu). This is OK if you know exactly what you do and if you have a "conditional break" - the base case - in there somewhere. But that seems not to be the case, so I'd propose you take a step back, scribble a layout of your functions and respective function calls onto a scrap sheet and then try to implement that.
# 7  
Old 03-12-2015
So I tried to map it out and explain the steps as well. The script is attached as well and it seems to work for the most part except for the two sections I added. I apologize in advance if I posted the text incorrectly I tried to follow a similar post. Thank you Smilie.

Code:
menu -> gjb2 -> name -> check -> position -> parse -> add2text -> additional? -> annovar -> menu or message and exit
^       ^
|		|               
|       |                                             
user    mecp2 -> name -> check -> position -> parse -> add2text -> additional? -> annovar -> menu or message and exit
choice  ^
		|
		|
	    phox2b -> name -> check -> position -> parse -> add2text -> additional? -> annovar -> menu or message and exit
        ^
		|
		|
		+----------------------------------------------------------------------------------------------------------+
		^
		|
		|
		exit

Code:
menu choice - user is prompted for selection (4 choices)	
selection - each selection has unique transcript assigned
name - python script to verify name syntax
check - user prompted to verify naming correct (Y/N) - after python script is run results of that appear on screen, so that the prompt can be answered
        if the answer is "Y" then next function (position), if "n" then return to function gjb2 and ${id}.txt cleared
position - python script to transfer ${id}.txt to annovar directory and convert to coordinates
parse - parse specific field to create ${id}_parse.txt
add2text - ${id}.txt is added to sanger.txt
additional - user is asked for additional data (Y/N) - if "Y" then goto to gjb2 function, if "N" then goto annovar function
annovar - perl script run on ${id}_parse.txt
after the script is run the user is told its completed and asked if there is more to do(Y/N) - if "Y" then menu function, if "N" then message and exit


Last edited by cmccabe; 03-12-2015 at 05:33 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[bash] Extra tab opens

Hello everyone, This code is working right using mate-terminal but with xfce4-terminal for some reason, it open up an extra tab... Could someone please help me out to understand why this is happening? #!/bin/bash cd "$(dirname "$0")"/files tab=" --tab" title=" --title" options=()... (2 Replies)
Discussion started by: soichiro
2 Replies

2. Shell Programming and Scripting

Bash Menu using zenity

Hi, I'm new to bash, and have an example menu script using Zenity. It works fine if the user enters A B or C, but if the user enters nothing, I can only figure out how to exit the script. How do I get the menu to reappear if no input is selected? The script is: title="Select example"... (2 Replies)
Discussion started by: allen11
2 Replies

3. Shell Programming and Scripting

New bash menu printing errors but closes too quickly

I am beginning to write a new version of the bash menu below. The previous version worked great and now when I start the updated bash it opens and a some lines print in the terminal and it closes quickly. I know there are errors but how can I see them or fix them, I tried set -x with the same... (12 Replies)
Discussion started by: cmccabe
12 Replies

4. Open Source

Bash menu not running

The perl command is not executing? I am trying to run the .pl in my cygwin home directory (C:\cygwin\home\cmccabe) using ${id}.txt.hg19_multianno.txt (located in the annovar directory) as the input file to be formatted and $FILENAME is the output file to be saved. The .pl is attached as... (8 Replies)
Discussion started by: cmccabe
8 Replies

5. Shell Programming and Scripting

Bash Script - Whiptail Menu Help!

Hello, Been trying to build a menu with whiptail lately. However, my code doesn't seems to be working even though when i compared to other similar code they looks the same. #!/bin/bash clear whiptail --msgbox "Entering networking sub-menu" 20 78 whiptail --title Networking --menu... (8 Replies)
Discussion started by: malfolozy
8 Replies

6. Red Hat

Bash: menu-complete and reverse

Hi, In the archives I found this: And this works fine. $if mode=vi "\C-0-": digit-argument TAB: menu-complete "\e But what I want is to reverse this. So I want that tab does reverse menu completion and shift tab does normal menu completion. Can anyone help me with this? Thanks (0 Replies)
Discussion started by: ozkanb
0 Replies

7. Shell Programming and Scripting

get chosen value from bash menu

Hi again :) This is just a sample whiptail menu. Works great, but have been trying to get the chosen value into a variable but failing pretty bad...its ther but unsure how to echo it out when needed #! /bin/bash #This is the menu whiptail --title "Menu example" --menu "Choose an... (9 Replies)
Discussion started by: olearydc
9 Replies

8. Shell Programming and Scripting

Help regarding a bash menu script

Greetings all, I'm having some trouble writing a menu drive bash script, actually coding the menu part was not difficult however its a problem with a menu option I'm having trouble with. My menu has 5 options, when the user selects the second option, they are then prompted to enter a number from... (5 Replies)
Discussion started by: Vitrophyre
5 Replies

9. Shell Programming and Scripting

Bash menu script

I have a main menu quit=n while do clear echo echo "1. General system information" echo "2. Hardware utilisation information" echo "3. File management" echo "4. User information" echo "5. Information on network connectivity" echo "6. Information on processes" echo "Q.Quit" ... (3 Replies)
Discussion started by: AngelFlesh
3 Replies

10. Programming

multiuser chat server closes when one client closes. code included

I have been trying to write a very basic chat program but at the moment I am having problems getting it to be multiuser as it closes all connections when one client shutsdown. I have also been having problems trying to get the program to display a list of usernames to the clients. I have tried... (0 Replies)
Discussion started by: dooker
0 Replies
Login or Register to Ask a Question