Search code examples
linuxparallel-processinggnuplotgnu-parallel

How can i replace variables inside quotation marks in parallel


I want to run on parallel a command that inputs two variables into a gnuplot file, I tried with:

parallel 'OMP_NUM_THREADS=11 gnuplot -e 'alpha={}; file="{}.txt"' graf_separation_time.gp' ::: 0 1 2 3 4 5 6 7 8 9 10 

But it doesn't work, any suggestions?


Solution

  • You are being hit by using ' inside '. Quoting is hard to get right, so it is often easier to define a function, test it and then have GNU Parallel call that.

    Untested:

    gp() {
      OMP_NUM_THREADS=11 gnuplot -e 'alpha='"$1"'; file="'"$1"'.txt" graf_separation_time.gp'
    }
    export -f gp
    parallel gp {} ::: 0 1 2 3 4 5 6 7 8 9 10 
    

    This will probably also work:

    parallel -q OMP_NUM_THREADS=11 gnuplot -e 'alpha={}; file="{}.txt" graf_separation_time.gp' ::: 0 1 2 3 4 5 6 7 8 9 10 
    

    Read more: https://www.gnu.org/software/parallel/man.html#quoting