Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to concatenate strings obtained from a .txt document with BASH script?

I have a txt document that contains a series of arguments that I want to pass to a script. Each argument is on a separate line. I want to make a BASH script that can concatenate these arguments (with white space between each one) and then execute the script with these concatenated arguments. This is the document (d.txt) content:

-format fastq

-in data/test_data.1.fq.gz

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

-in2 data/test_data.2.fq.gz

-reference hg19

-alignment

-variantcalling

-annotation

-iobio

-out outdir/

-BED

I have tried to do it in the following way but it gives me an error. Instead of concatenating the s

trings, it interprets them as commands. does anybody know how I can fix it?

`

#!/bin/bash

while IFS= read -r line
do
  
  $var=$var$line
  echo $var

done < d.txt

`
This is the error I get:

./script.sh: line 6: =-format: order not found

./script.sh: line 6: =-in:order not found

./script.sh: line 6: =-in2: order not found

./script.sh: line 6: =-reference: order not found

./script.sh: line 6: =-alignment: order not found

./script.sh: line 6: =-variantcalling: order not found

./script.sh: line 6: =-annotation: order not found

./script.sh: line 6: =-iobio: order not found

./script.sh: line 6: =-out: order not found

./script.sh: line 6: =-BED: order not found

>Solution :

There is only a little mistake in assigning the Variable.

var=$var$line

instead of

$var=$var$line
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading