Reputation: 14343
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.
Upvotes: 0
Views: 339
Reputation: 532333
You just have a slight syntax issue in your string:
end_cm1="fastqc -o $out_path --noextract -fastq $files1"
$enc_cm1
Having said that, @ams is right about not needing to assign this
to a string in the first place, and about the risks involved
in not quoting $files1
.
Upvotes: 0
Reputation: 25599
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
Upvotes: 3