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 :).
#!/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() {"
.....
.....