The script below is an attempt to combine 3 shells into 1.
The first part: match.sh
prompts the user for an id of a patient and runs a match script based on the response of "y" or "n". After completing the user is asked if there are additional patients, and based on "y" or "n" a certain action is followed.
The second part: convert2annovar.sh
prompts the user for an id of a patient and runs a conversion script based on the response of "y" or "n". After completing the user is asked if there are additional patients, and based on "y" or "n" a certain action is followed.
The third part: table_annovar
prompts the user for the type of analysis and runs a script based on the response of "y" or "n". After completing the user is asked if there are additional patients, and based on "y" or "n" a certain action is followed.
+ ~ $ sh annovar.sh
What is the id of the patient to be matched : 3
': not a valid identifier `id
What panel: 3
': not a valid identifier `panel
annovar.sh: line 4: syntax error near unexpected token `$'in\r''
'nnovar.sh: line 4: ` case "$id" in
2 ~ $ sh annovar.sh
What is the id of the patient to be matched : a
': not a valid identifier `id
What panel: b
': not a valid identifier `panel
annovar.sh: line 4: syntax error near unexpected token `$'in\r''
'nnovar.sh: line 4: ` case "$id" in
2 ~ $
The code is similar in that it is the same basic structure with additional functionality trying to be added. Being new to awk and learning I tried following your example (thank you for that):
#!/bin/bash
show_menu=true
menu=( "[yY]" "[nN]" )
func_show() { # "MESSAGE STRING"
# Prints passed argument
# Returns nothing
printf '\n\t%s\n\n' "$1"
}
#
# Display & Action
#
clear
while $show_menu
do printf '#----------------------#\n%s\n' "Are there additonal patients to be matched"
select entry in "${menu[@]}" Back
do case "$entry" in
Back) show_menu=false
;;
"[yY]") func_show "perl -aF/\\t/ -lne 'BEGIN{%m=map{chomp;s/\cM|\cJ//g;$p=join("\t",(split/\t/)[4,5]);($p,$_)} <>;$m{"#CHROM\tINFO"}=$m{"Chr\tSegment Position"}};/SEGPOS=(\d+)/ || /\t(INFO)\t/ or next;$p=$F[0]."\t".$1;exists $m{$p} and print join("\t",$_,$m{$p})' ${id}_${panel}_${OMR}.txt < ${id}_${panel}_${OMR}_Filtered.vcf > ${id}_matched.vcf (index id 0) :: $entry"
;;
"${menu[2]}") func_show "printf "Does the file need to be converted : " ; read id :: ${menu[${#menu[@]}-1]}"
;;
*)
esac
break
done
done
This is just the first section of the script. If a "Y" response is given it will run a perl command, but if "N' is given it prompts the user and thats all. Is that correct? Thank you :).