Search code examples
bashwhile-looppipeline

Execute commands from a single column of an input file


I have very little experience with bash, but am attempting to put together a pipeline that reads in and executes commands line by line from an input file. The input file, called "seeds.txt", is set up like so

program_to_execute -seed_value 4496341759106 -a_bunch_of_arguments c(1,2,3) ; #Short_description_of_run
program_to_execute -seed_value 7502828106749 -a_bunch_of_arguments c(4,5,6) ; #Short_description_of_run

I separated the #Short_descriptions from the commands by a semi-colon (;) since the arguments contain commas (,). When I run the following script I get a "No such file or directory" error

#!/bin/bash

in="${1:-seeds.txt}"

in2=$(cut -d';' -f1 "${in}")

while IFS= read -r SAMP
    do
    $SAMP 

done < $in2

I know that seeds.txt is getting read in fine, so I'm not sure why I'm getting a missing file/directory message. Could anyone point me in the right direction?


Solution

  • you can try as below with eval...not very safe though, see this for more info

    while read line; do eval "$line" ; done < <(cut -d';' -f1 seeds.txt)