从阵馈命令行参数 [英] command line arguments fed from an array
问题描述
我想执行一个复杂的bash命令,利用多头排列作为参数提供的数据。我猜它必须使用某种形式的子shell。
I'd like to perform a complicated bash command, using data fed from a long array as arguments. I guess it has to use a subshell in some way.
例如,代替可行转换-size 100x100的XC:黑白色-fill -draw点1,1-draw点4,8-draw点87,34等等等等image.png
我想使用不同的逻辑,其中的参数在同一个命令中给出,更像
I want to employ a different logic where the arguments are given in the same command, more like
转换-size 100x100的XC:黑白色-fill $(因为我在1,1 4,8 87,34等等等等; -draw点$ I;完成)image.png
不工作,因为我$ PTED是作为命令insted的一个参数的相互$ P $。
convert -size 100x100 xc:black -fill white $(for i in 1,1 4,8 87,34 etc etc; -draw "point $i"; done) image.png
which doesn't work, as the $i is interpreted as a command insted of an argument.
请注意,因为我在...;转换做... $我......;完成将无法工作。在 -draw点X,Y
系列的参数必须是相同的单次运行convert命令,因为转换不接受现有图像-draw参数。
Please note that "for i in ...; do convert ...$i...; done" will not work. The -draw "point x,y"
series of arguments must be in the same single run convert command, as convert doesn't accept -draw parameter in existing images.
推荐答案
树立的 -draw
参数数组第一位。
Build up an array of -draw
arguments first.
for pt in 1,1 4,8 87,34; do
points+=(-draw "point $pt")
done
convert -size 100x100 xc:black -fill white "${points[@]}" image.png
这篇关于从阵馈命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!