0

What is wrong with these lines?

FASTAQ1 = "/home/mdb1c20/my_onw_NGS_pipeline/files/fastq/W2115220_S5_L001_R1_001.fastq"
FASTAQ2 = "/home/mdb1c20/my_onw_NGS_pipeline/files/fastq/W2115220_S5_L001_R2_001.fastq"
DIRECTORY = "/home/mdb1c20/my_onw_NGS_pipeline/scripts_my_first_NGS"

They are in a .conf file with other similar variables. The only difference is that these three are created with printf

printf 'FASTAQ1 = "%s"\n' "$FASTA1" >> "$DIRECTORY/$filename1/scripts/shortcut.config"
printf 'FASTAQ2 = "%s"\n' "$FASTA2" >> "$DIRECTORY/$filename1/scripts/shortcut.config"
printf 'DIRECTORY = "%s"\n' "$DIRECTORY" >> "$DIRECTORY/$filename1/scripts/shortcut.config"

When a script I am using open the .confi file its says that FASTAQ1: command not found

Apart from these three, the rest of variables were created manually in a archive .conf file but the script add these three on the go. The only thing I haven't tried because I don't know how to do that is to remove the white spaces before and after the equal simbol?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • `I don't know how` like, how to edit a file? – KamilCuk Jan 05 '22 at 21:03
  • Please add a suitable shebang (`#!/bin/bash`) and then paste your script at http://www.shellcheck.net/ and try to implement the recommendations made there. – Cyrus Jan 05 '22 at 21:05
  • What's a `.conf` file (or is it actually a `.config` file)? By which I mean, the filename extension does not by itself convey either the expected syntax or the significance of the contents. That leaves us with very little to go on. – John Bollinger Jan 05 '22 at 21:06
  • None of the answers in the duplicate question suggests quoting. – konsolebox Jan 05 '22 at 21:19

2 Answers2

1

If you intended to source your configuration file, you should have used printf this way:

printf 'FASTAQ1=%q\n' "$FASTA1" >> "$DIRECTORY/$filename1/scripts/shortcut.config"

This allows you to store the value safely regardless if it has spaces or quotes.

The error was caused by the assignment command being interpretted as a simple command instead because of the spaces around the equal sign.

Alternatively for Bash 4.4+, you can use @Q expansion:

echo "FASTAQ1=${FASTA1@Q}" >> "$DIRECTORY/$filename1/scripts/shortcut.config"
konsolebox
  • 72,135
  • 12
  • 99
  • 105
1

In bash, this:

var = value

is not the same as this:

var=value

The first example runs a command named "var" and passes it two arguments "=" and "value".

The second example sets a variable called "var" to "value".

It was hard to find this detail in the Bash manual, but the difference is between simple commands and assigning to variables, or shell parameters.

MattArmstrong
  • 349
  • 3
  • 9