Automaticaly create function based off user input


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Automaticaly create function based off user input
# 1  
Old 12-28-2017
Automaticaly create function based off user input

I am trying to create a bash script that will create new function by using the user input. The below will create the necessary files in the correct format, however when it comes to the # create function I am at a loss.
If the name entered was NEWNAME and the genes were GENE1,GENE2 then two files would be created using NEWNAME. That executes as expected and in the # convert name to lower case, NEWNAME is converted to lowercase as variable string. This variable starts the function. The ... in the code are mostly hardcoded lines that use either NEWNAME or $string in them. I am not sure if this is the best way but maybe its a start. Thank you Smilie.

Code:
#!/bin/bash

# enter name
printf "What is the name of the panel (please use CAPS): "; read name

# enter gene input
printf "%s \n" "Please enter gene(s), use a comma between multiple:" ; IFS="," read -a genes
for (( i = 0; i < ${#genes[@]}; i++ ))
do
    printf "%s\n" "${genes[$i]}" > /home/cmccabe/Desktop/NGS/panels/new.txt
    # remove line endings and trim
     sed 's/\r$//' < /home/cmccabe/Desktop/NGS/panels/new.txt | sed 's/^[ \t]*//;s/[ \t]*$//' > /home/cmccabe/Desktop/NGS/panels/${name}_unix_trim.bed
done

# create total target length for input
awk 'NR==FNR{A[$1];next}$1 in A' /home/cmccabe/Desktop/NGS/panels/${name}_unix_trim.bed /home/cmccabe/Desktop/NGS/bed/bedtools/IDP_total_target_length_by_panel/IDP_unix_trim_total_target_length.bed > /home/cmccabe/Desktop/NGS/bed/bedtools/IDP_total_target_length_by_panel/${name}_unix_trim_total_target_length.bed

#-------------------------------------------------------------------------#
# convert name to lower case
y="$name"
val=$(echo "$y" | tr '[:upper:]' '[:lower:]')
string="$val"

echo "This is the new panel to add" $string

# create function
printf "$string() {"
.....
.....

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to search file based off user input then create new file

In the below bash a file is downloaded when the program is opened and then that file is searched based on user input and the result is written to a new file. For example, the bash is opened and the download.txt is downloaded, the user then enters the id (NA04520). The id is used to search... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. UNIX for Dummies Questions & Answers

Split files based on user input

Hi All, I have a UNIX script which reads "PxyType" (read PxyType) as input from user and a file (eg : "File.json") with the list all PxyType's. Based on the user input for "PxyType" in "File.json", I want to redirect each matched line to a different file ("File1,2,3,..json"). Can you... (7 Replies)
Discussion started by: Deena1984
7 Replies

3. Homework & Coursework Questions

Function to Check if string input from user is alphabetic only

Good Evening. I'm new to C. Can you please help me. I'm creating an error checking function, user will input a string, this will check if the input is all alphabet or all letters only. If there is a digit or other special char, it will print Error then ask input from user again. Here's my... (1 Reply)
Discussion started by: eracav
1 Replies

4. Shell Programming and Scripting

Script interacts with user , based on user input it operates

i have a script which takes input from user, if user gives either Y/y then it should continue, else it should quit by displaying user cancelled. #!/bin/sh echo " Enter your choice to continue y/Y OR n/N to quit " read A if then echo " user requested to continue " ##some commands... (7 Replies)
Discussion started by: only4satish
7 Replies

5. Shell Programming and Scripting

create an array which can store the strings from the user input in shell script

I want to create an array which can store the strings from the user input in shell script . example :- I want to store the 5 fruits name in a single array which the user provides . (1 Reply)
Discussion started by: Pkast
1 Replies

6. Shell Programming and Scripting

no chance to input passwd when create new user in loop

Hi Dears, I have one script to create new users with information in one plain text file. This script will read all lines in the file and create one users for one line. Sample file: #action;login,full name title,expire date,project +;gmwen,Bruce Wen QA,04/01/2012,BT +;xxdeng,Shown Deng... (4 Replies)
Discussion started by: crest.boy
4 Replies

7. Shell Programming and Scripting

How to automatically create variables from user input in ksh?

I need some help to write a ksh script. My code so far (pretty bad, sorry): #! /bin/ksh echo "Calculate average" UserDecision=y while test $UserDecision = y do echo "Enter a number: " read Number1 echo "Enter a number: " read Number2 echo "Do you want to enter another number?... (2 Replies)
Discussion started by: johnagar
2 Replies

8. Shell Programming and Scripting

every time user input create array perl

Hi, How to create array every time user input and store user input and display all array print " Enter input " my @input = split(' ', $input) chmop($input = <STDIN>; foreach ($input) { @array= @input; } print @array"\n"; (1 Reply)
Discussion started by: guidely
1 Replies

9. Shell Programming and Scripting

Append file based upon user input-- solved

Ok, I have a script with a commandline option that allows the user to add a custom function to the script file. I have tried everything in my limited knowledge of sed to get this to work and keep coming up short. I need sed to search for a line starting with a pattern, I've got that part so far,... (0 Replies)
Discussion started by: DC Slick
0 Replies

10. Shell Programming and Scripting

Create a multi user input form

Hi All, Please ignore if terminology used is incorrect as I am new to Unix. I want to create a Multi user input form which looks something like this: ABCD TOOL Logged User: abcd12 ... (4 Replies)
Discussion started by: vidhu0007
4 Replies
Login or Register to Ask a Question