Search code examples
bashfastq

Executing a command in a string in bash


I have a string that contains a command that I want to execute in a bash script. How can I do that? Sorry for so basic question but I am new in bash. This is my code:

echo "What is the path to save the result files?"
read out_path

end_cm1=$"fastqc -o "$out_path$" --noextract -fastq "$files1

And I want to execute the instruction that is in the end_cm1 variable.


Solution

  • First, you don't have to put that command in a string at all: you can just do this:

    fastqc -o "$out_path" --noextract -fastq $files1
    

    (And I'd recommend putting $out_path in quotes here in case the path has a space in it. I've not put $files1 in quotes because your variable is plural so I assume there's more than one; you should beware spaces in those file names also.)

    Second, the answer to the question you asked is eval:

    eval $end_cm1