Bash menu opens and closes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash menu opens and closes
# 8  
Old 03-12-2015
Wouldn't sth. like this make more sense (just an idea):
Code:
user choice 
|
v 
menu +> gjb2 -> name -> check -> position -> parse -> add2text -> additional? -> annovar -------+
  ^  |    ^                                                            v                        |
  |  |    +<---------------------------------------------------------<-+                        |
  |  |                                                                                          |
  |  +> mecp2 -> name -> check -> position -> parse -> add2text -> additional? -> annovar ------+
  |  |    ^                                                            v                        |
  |  |    +<---------------------------------------------------------<-+                        |
  |  |                                                                                          |
  |  +> phox2b -> name -> check -> position -> parse -> add2text -> additional? -> annovar -----+
  |  |    ^                                                            v                        |
  |  |    +<---------------------------------------------------------<-+                        |
  |  |                                                                                          |
  |  +> exit                                                                                    |
  +---------------------------------------------------------------------------------------------+

And it looks like there's quite some more potential to optimize.
# 9  
Old 03-12-2015
The 'gjb2' function as no closing bracket }.
And similar to RudiC, i'd highly recomend that the default behaviour of funtions should be return.

However, the menu function should be the only function calling others, which already is.
Also use either break or return to exit a case statement within a function.

As you already have split up the functionality to functions.
It is recomended to 'list' the functions, rather than calling 1 function which calls the other which calls another, which calls another - as one might produce unexpected behaviour.

For better readability, try to always use the same indention-blocks.
Usualy thats either 4 or 8 spaces or tabs.

hth

---------- Post updated at 22:53 ---------- Previous update was at 22:40 ----------
Since the follow up handling for all the 3 functions is identical, i'd attempt something like:
Code:
user choice 
|
|         +<--------------------------------------------------------------\
v         V                                                                \
menu +> gjb2  ->  \                                                         \
  ^  |             \                                                         \
  |  |              \                                                         \
  |  |               \                                                         ^
  |  +> mecp2 -------- +-> name -> check -> position -> parse -> add2text -> additional? -> annovar ------+
  |  |    ^           /                                                        v                          |
  |  |    +<-----------------------------------------------------------------<-+                          |
  |  |              /                                                         /                           |
  |  +> phox2b ->  /                                                         /                            |
  |  |    ^                                                                 /                             |
  |  |    +----------------------------------------------------------------/                              |
  |  |                                                                                                    |
  |  +> exit                                                                                              |
  +-------------------------------------------------------------------------------------------------------+

As on grab the data from one of the selected functions, and pass it to the follow up functions, which seem to be identical for each of the selectables...

hth
# 10  
Old 03-12-2015
The 3 user choices are virtually the same except for the sed which applies the correct transcript with the user choice. For example, if the choice is GJB2 then the NM_ is different then if the user choice was MECP2. I am out of my element here and am needing some expert assistance in making this code work. I am trying to learn all the terms, but admittedly slower it seems. Thank you Smilie.
# 11  
Old 03-13-2015
Make those 2 tasks, each a single function that works independant of each other.
Actualy you've already done so Smilie

Its all about the maintask function...
Code:
#!/usr/bin/env bash
#
#
# Functions
#
	function XY...
	...
	...
	
	function menu() {
	# Shows the menu and loops until Exit has been selected
	while true
		do
			printf "\n Welcome to annovar, please make a selection from the MENU \n
			==================================\n\n
			\t 1  GJB2 analysis\n
			\t 2  MECP2 analysis\n
			\t 3  Phox2B analysis\n
			\t 4  Exit\n\n
			==================================\n\n"

			printf "\t Your choice: "; read menu_choice

			case "$menu_choice" in
			1) maintask gjb2 ;;
			2) maintask mecp2 ;;
			3) maintask phox2b ;;
			4) printf "\n Bye! \n\n"; return 0 ;;
			*) printf "\n Invalid choice."; sleep 2 ;;
			esac
		done
	}
	function maintask() {
	# First and only argument expected to be the functions name!
		loop=true
		while $loop
		do
			$1       ### This would be one of:: gjb2 mecp2 phox2b
			check || break
			position
			convert
			add2text
			read -n1 -p "Do an additional patient for $1?"  yesno
			[ "$yesno" = y ] || loop=false
		done
		annovar
	}
#
# Action & Display
#
	menu

Hope this helps
# 12  
Old 03-13-2015
Thank you for the tips and help (very useful)... for the check function a file is created in C:/Users/cmccabe/Desktop/annovar/${id}.txt (attached), that has a warning column in it at $2 . If the variant has an error message in it can that be displayed as part of the check function? And if that field is blank "no errors" is displayed?

Also, in the echo -n what is the correct syntax to clear two or three files? Thank you Smilie



Code:
 check() {
    printf "\n\n"
    " warning from ${id}.txt in annovar directory"
    printf "Is the variant correct?  Y/N "; read match_choice

    case "$match_choice" in
        [yY]) id=""; position ;;
        [nN]) id=""; echo -n "" > C:/Users/cmccabe/Desktop/Python27/${id}.txt ; gjb2 ;;  
    esac
}

# 13  
Old 03-13-2015
Code:
    printf "\n\n"
    " warning from ${id}.txt in annovar directory"

Try:
Code:
    printf "\n\nwarning from ${id}.txt in annovar directory"

Just seeing i'm running out of time in RL...
I'm not good at awk yet, but maybe this could help to display the error message if one exists.
Code:
awk '
	NR==1
	if($2 != ""){
		print $2
	}'C:/Users/cmccabe/Desktop/Python27/${id}.txt

hth
This User Gave Thanks to sea For This Post:
# 14  
Old 03-13-2015
Quote:
Originally Posted by cmccabe
... ... ...

Also, in the echo -n what is the correct syntax to clear two or three files? Thank you Smilie

... ... ....
The command to create a regular file if it did not already exist or to truncate it to size zero if does already exist is:
Code:
> pathname

For more than one file, the syntax is:
Code:
> pathname1
> pathname2
...
> pathnameN

If the pathnames contain directories as well as a filename, that/those directory/directories must already exist for this to work. If you don't know if there might be missing directories, you can use:
Code:
mkdir -p "$(dirname pathname)" && > pathname

This User Gave Thanks to Don Cragun For This Post:
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