1

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?

Jarl
  • 45
  • 5

3 Answers3

2

Using GNU Parallel it looks like this:

cut -d';' -f1 seeds.txt | parallel
Ole Tange
  • 31,768
  • 5
  • 86
  • 104
1

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)
nullPointer
  • 4,419
  • 1
  • 15
  • 27
  • Thank you, this does exactly what I want. In this case, where I'm the only one making the seeds.txt file, it seems like the safety concern with `eval` is less of an issue. – Jarl Feb 12 '20 at 17:20
1

Just in case you want to avoid eval

while read -ra line; do command "${line[@]}"; done < <(cut -d';' -f1 seeds.txt)

Note this solution does not work if the program/utility is not an executable within your PATH, e.g. you wan to use a function or an alias. Not sure if the eval solution can do that too. Kudos to the cut solution!

Jetchisel
  • 7,493
  • 2
  • 19
  • 18