Yes or No selection within bash function


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Yes or No selection within bash function
# 1  
Old 06-24-2015
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.

Code:
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
}

# 2  
Old 06-24-2015
The case syntax:

Code:
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.

Code:
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.
Code:
for v in ${variant[@]}; do
        #do something with "${v}"

This User Gave Thanks to Aia For This Post:
# 3  
Old 06-24-2015
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?
This User Gave Thanks to RudiC For This Post:
# 4  
Old 06-24-2015
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 Smilie.
# 5  
Old 06-24-2015
Read posts in these fora and compare readable to unreadable ones.
# 6  
Old 06-24-2015
Quote:
Originally Posted by cmccabe
[...] Btw, I have been trying to find tutorials or books on how to write code more clearly/readable, do you have any sugesstions? [...]
Google style I think is worth having a read. Look at formatting.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash selection of files with similar name

Hi all, This is my first day on Linux shell!!! So, I am trying to write a script that that will pick up pairs of files with the same name (not the same content) but that are different in one character (one is *R1 the other is *R2)... Something like: look ate the files, whenever they are the... (3 Replies)
Discussion started by: ALou
3 Replies

2. Shell Programming and Scripting

Bash function problem

I am trying to figure out why I am having a "problem" with some functions in a bash script I am running. The reason for air quoting is that the functions are working, they are just not displaying anything to screen when called from another function. Here's an example: function Create_Input {... (6 Replies)
Discussion started by: dagamier
6 Replies

3. Shell Programming and Scripting

Bash function, for BSD

I am putting this thread to shell-threads, because it is about how to make a function work properly. I need a hint for declaring a function right, it has been more than a year I did not work that straight with bash. So my aim is to turn off the eth0 (as it would be in linux, and bge0 in bsd ),... (2 Replies)
Discussion started by: 1in10
2 Replies

4. UNIX for Dummies Questions & Answers

Bash INKEY$ function...

This is probably common knowledge to the professionals but not so much for amateurs like myself. This is a code snippet for the equivalent of BASIC's... LET char$=INKEY$ As the timeout parameter cannot be less than 1 second then this is the only limitation... It is a single line... (5 Replies)
Discussion started by: wisecracker
5 Replies

5. Shell Programming and Scripting

Bash function

startvm() { startguest } Is there a way use one line to get this ? actually I want startvm=startguest (5 Replies)
Discussion started by: yanglei_fage
5 Replies

6. Shell Programming and Scripting

bash read within function with arguments

I have trouble getting this logic to work #!/bin/bash function assign_var(){ while do read -p "$2 :" $3 done } assign_var '$IPADDRESS' ipaddress IPADDRESS Basicly, i want to make sure that entry is made (i can add more sophisticated checks later), but the idea is to recycle... (11 Replies)
Discussion started by: serverchief
11 Replies

7. Shell Programming and Scripting

BASH function error

Hey everyone. I am currently testing my first function based BASH script. The ultimate goal is going to be moving logs from point A to point B (or if B is down, to point C). Part of this involves the following function: function testAlive{ ping -c 1 -q $1 } Now when I run ping -c... (1 Reply)
Discussion started by: msarro
1 Replies

8. Shell Programming and Scripting

bash search function

I want to have a function with a similar interface: search *.cpp asdf that will search recursively all directories for *.cpp file, containing line 'asdf' inside. I tried this: function search { find . -name "$1" | xargs grep -li $2; } But it doesn't work all the time. For example, if i run it... (3 Replies)
Discussion started by: doze
3 Replies

9. Shell Programming and Scripting

Need help in using power function in Bash

Hi, I would like to use a power function in Bash in an awk '{ } . e.g pow(2,3)=8 Any suggestion? I try to find online resources but most of them stated by using BC. Please advise. Thanks. (3 Replies)
Discussion started by: ahjiefreak
3 Replies

10. Shell Programming and Scripting

Need assistance with bash function

Hi all! I need a little help with an imbedded fuction I am trying to write. What I am trying to do is go to a series of hosts and get the contents of an XML file, storing some of the data, along with the name of the host it was gathered from. My intent is to store this in an array for later... (1 Reply)
Discussion started by: _jade_
1 Replies
Login or Register to Ask a Question