Sponsored Content
Top Forums Shell Programming and Scripting Bash function using variable in it syntax error Post 302994491 by cmccabe on Thursday 23rd of March 2017 12:36:53 PM
Old 03-23-2017
Bash function using variable in it syntax error

The below bash function uses multiple variables CODING, SAMPLE, SURVEY, andvariant
in it. The user selects the cap function and details are displayed on the screen using the $SURVEY variable, the directory is changed to $SAMPLE and the samples.txt is opened so the user can select the sample to use. The numeric id is entered along with some $variant (could be multiple) and the $CODING:$variant are written to an out.txt file and stored /home/cmccabe/cap/TGS. I am getting a syntax error on the last line looking for the matching ' and am not sure if I am using the variables correctly in the function. Thank you Smilie.

samples.txt in $SAMPLE
Code:
test-01
test-02
test-03
test-04

$SURVEY format
Code:
Survey id
name
details

$CODING format
Code:
NM_000012.3

Code:
cap() {
CODING=/home/cmccabe/cap/TGS/NM.txt
SAMPLE=/home/cmccabe/cap/TGS
SURVEY=/home/cmccabe/cap/TGS

printf "The survey being used is and here are the details:" "$SURVEY\survey.txt "

PS3="please select a file to analyze with a panel: "

cd "$SAMPLE"
select file1 in $(cat samples.txt)
do	[ "$file1" != "" ] && break
done
      printf "FILE is: ${file1} and will be used for annotation\n"
      read -r -p "Is this correct? [y/N] " response
if [[ $response =~ ^[nN][oO]?$ ]]
then
echo 'please try again'  && return
    printf "\n\n"
    printf "What is the id of the CAP sample getting gene annotation : "; read id
	printf "Please enter the variant(s), the following are examples"
	echo " c.274G>T or c.274-10G>T or c.*18_*19delGCinsAA"
	
	printf "and please 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 ${CODING}:%s\n ${variant[$i]} >> /home/cmccabe/cap/TGS/out.txt
        done
}


Last edited by cmccabe; 03-23-2017 at 01:39 PM.. Reason: fixed format and added details
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash: how to call function having it's name in variable?

Hello. Looking for a method of modularizing my bash script, I am stuck with such a problem. For example, I have: MODULE_NAME="test" FUNCTION_NAME="run" How do I can a function with name test_run? (4 Replies)
Discussion started by: FractalizeR
4 Replies

2. Shell Programming and Scripting

BASH Script syntax error

I'm trying to write a simple script that takes all the .tar.gz files in a directory and verifies them by using the gzip -tv command: for zip in *.tar.gz do gzip -tv $zip if ; then #Check return code from tar echo "File ${zip} verified OK." exit... (4 Replies)
Discussion started by: kelldan
4 Replies

3. Shell Programming and Scripting

bash syntax error: command not found

I am trying to create a shell that asks the user to enter their name, and compare it to my own by saying we have the same name or saying my name and that they have a nice name too. Here is my script... #!/bin/bash-x echo "Enter your name". read name if then echo "My name is Adam too"... (1 Reply)
Discussion started by: amaxey45
1 Replies

4. Shell Programming and Scripting

Syntax Error while using CMP function

Hi All, I am getting a syntax error message while trying to compare 2 files using the compare function (LINUX) command substitution: line 79: syntax error near unexpected token `(' command substitution: line 79: `cmp -s <(tr , \n < $COMMON_TMP/nt_per_gs.done | sort) <(tr , \n <... (5 Replies)
Discussion started by: dsfreddie
5 Replies

5. Shell Programming and Scripting

Variable syntax error in $?

hi all , i just tried to take the status of previous command inside the script using echo $?. It throws me a variable syntax error , but when i use echo $? as an individual command it works perfectly . can anyone Please tell me why am getting a variable syntax error when i use echo $?... (7 Replies)
Discussion started by: Rahul619
7 Replies

6. Shell Programming and Scripting

BASH: variable and function scope and subscripts

Hi, I'm a Delphi developer new to linux, new to this forums and new to BASH programming and got a new task in my work: maintaining an existing set of BASH scripts. First thing I want to do is making the code more reliable as in my opinion it's really bad written. So here's the quest: I'm... (6 Replies)
Discussion started by: rse
6 Replies

7. Shell Programming and Scripting

Function works, trigger causes syntax error, whats my fault??

Needing a hint. Creating that function called Meter my simple script works well. What I want now is to start the last four commented lines to include or trigger a reaction, if there are more than n lines in that .txt-file it shall display that message for example. But the interpreter says there is... (3 Replies)
Discussion started by: 1in10
3 Replies

8. Shell Programming and Scripting

Bash syntax error

while read line do mkdir $line scp -r Docking_results/docking_$line.pdb $line/ cd /$line/ set a=`grep ENDMDL docking_'$line'.pdb | wc -l` set b=`expr $a - 2` csplit -k -s -n 3 -f docking_'$line'. docking'$line'.pdb '/^ENDMDL/+1' '{'$b'}' foreach f (... (4 Replies)
Discussion started by: chrisjorg
4 Replies

9. Shell Programming and Scripting

-bash: syntax error near unexpected token `('

// AIX 6.1 I am getting a syntax error below. Please advise what to be corrected. :confused: runmqsc CERN.$(echo `hostname` | cut -d'.' -f1 | tr '' '').$(echo $environment | tr '' '') <<! | egrep -i '(FROM.NC.APPLIANCE)' | sort -u |awk '{print $2}' | cut -d '(' -f2 | cut -d ')' -f1 |... (1 Reply)
Discussion started by: Daniel Gate
1 Replies

10. Shell Programming and Scripting

Syntax error in subtraction in Bash

I am sharing a code snippet. for (( i=0; i<=$(( $count -1 )); i++ )) do first=${barr2} search=${barr1} echo $first echo "loop begins" for (( j=0; j<=5000; j++ )) do if } == $search ]]; then echo $j break; fi done second=${harr2} echo $second (2 Replies)
Discussion started by: ngabrani
2 Replies
All times are GMT -4. The time now is 01:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy