Ich möchte eine Liste von Gnuplot-Befehlen parallel ausführen.
Ich erhalte die Fehlermeldung „Option nicht erkannt“:
$ ./parallel-plot-sine.sh | parallel -q gnuplot
unrecognized option -e "set terminal pngcairo; set output '100.png'; set title 'Sample rate: 100'; set key left box; set autoscale; set samples 100; plot [-30:20] sin(x)"
Ich glaube, dies deutet darauf hin, dass Gnuplot mit dem Befehl, den es erhält, nicht zufrieden ist, aber ich kann nicht herausfinden, warum.
Das Shell-Skript parallel-plot-sine.sh
stellt die Befehle zusammen, die in Gnu Parallel eingespeist werden:
#!/bin/bash
# Compose command-lines to run in parallel
command_array=()
for fs in $(seq 100 100 1000); do
command_array+=("-e \"set terminal pngcairo; set output '${fs}.png'; set title 'Sample rate: $fs'; set key left box; set autoscale; set samples $fs; plot [-30:20] sin(x)\"")
done
# Print command strings to output for gnu parallel
for cmd in "${command_array[@]}"; do
printf "%s\n" "$cmd"
done
Dies druckt:
$ ./parallel-plot-sine.sh
-e "set terminal pngcairo; set output '100.png'; set title 'Sample rate: 100'; set key left box; set autoscale; set samples 100; plot [-30:20] sin(x)"
-e "set terminal pngcairo; set output '200.png'; set title 'Sample rate: 200'; set key left box; set autoscale; set samples 200; plot [-30:20] sin(x)"
-e "set terminal pngcairo; set output '300.png'; set title 'Sample rate: 300'; set key left box; set autoscale; set samples 300; plot [-30:20] sin(x)"
-e "set terminal pngcairo; set output '400.png'; set title 'Sample rate: 400'; set key left box; set autoscale; set samples 400; plot [-30:20] sin(x)"
-e "set terminal pngcairo; set output '500.png'; set title 'Sample rate: 500'; set key left box; set autoscale; set samples 500; plot [-30:20] sin(x)"
-e "set terminal pngcairo; set output '600.png'; set title 'Sample rate: 600'; set key left box; set autoscale; set samples 600; plot [-30:20] sin(x)"
-e "set terminal pngcairo; set output '700.png'; set title 'Sample rate: 700'; set key left box; set autoscale; set samples 700; plot [-30:20] sin(x)"
-e "set terminal pngcairo; set output '800.png'; set title 'Sample rate: 800'; set key left box; set autoscale; set samples 800; plot [-30:20] sin(x)"
-e "set terminal pngcairo; set output '900.png'; set title 'Sample rate: 900'; set key left box; set autoscale; set samples 900; plot [-30:20] sin(x)"
-e "set terminal pngcairo; set output '1000.png'; set title 'Sample rate: 1000'; set key left box; set autoscale; set samples 1000; plot [-30:20] sin(x)"
Diese Befehle funktionieren einzeln wie folgt:
gnuplot -e "set terminal pngcairo; set output '1000.png'; set title 'Sample rate: 1000'; set key left box; set autoscale; set samples 1000; plot [-30:20] sin(x)"
Antwort1
GNU Parallel setzt Eingaben standardmäßig in Anführungszeichen. Sie geben Eingaben ein, die bereits in Anführungszeichen gesetzt sind. Es gibt mehrere Lösungen.
Ändern Sie die Eingabe von:
-e "set terminal pngcairo; set output '100.png'; set title 'Sample rate: 100'; set key left box; set autoscale; set samples 100; plot [-30:20] sin(x)"
Zu:
set terminal pngcairo; set output '100.png'; set title 'Sample rate: 100'; set key left box; set autoscale; set samples 100; plot [-30:20] sin(x)
und Renn:
... | parallel gnuplot -e
Alternative:
... | parallel eval gnuplot
# Requires version >= 20190722
... | parallel gnuplot {=uq=}