Bash Makefile 连接数组
我正在尝试为文件名数组提供一个路径,然后对它们执行某些操作并填充到字符串(格式正确)。这是代码/概念
13 javascripts: setup
14 i=0
15 for source in `ls ${SOURCE_DIR}/js/*.coffee | sed -e "s:^.*\/\(\w*\).coffee:\1:"`; do\
16 sources[i]="--input ${OUTPUT_DIR}/js/$$source.js";\
17 i=$(i+1);\
18 echo "Compiling coffee script: $$source.coffee";\
19 coffee -bo "${OUTPUT_DIR}/js" -c "${SOURCE_DIR}/js/$$source.coffee";\
20 done;\
21 python2 ${CLOSURE_PATH}/bin/calcdeps.py --path ${CLOSURE_PATH}/../\
22 $${sources[0]} --compiler_jar ${CLOSURE_PATH}/bin/compiler.jar\
23 --output_mode compiled > ${OUTPUT_DIR}/compiled.js;
24 echo "Cleaning ${OUTPUT_DIR}/js"
25 @rm -rf ${OUTPUT_DIR}/js
所以,我想将一个数组连接到一个字符串并将其导出到第 21
行上以 python2 开头的命令。问题是我什至无法访问 sources
变量内的任何值。当我用 echo $${sources[0]}
替换第 21
行时,它会输出 --input output/js/main.js
这是正确的输入。
该怎么办?另外,如果您能指出 gnu.org
上没有的任何 bash/Makefile 指南(很长 = 耗时),我将不胜感激。我有使用几种语言进行编程的经验,但很少有 bash 的经验,所以在这一点上,这让我笑了。
谢谢。
I'm trying to glob a path for array of filenames, then do something with them and populate to a string (formatted properly). Here's the code/concept
13 javascripts: setup
14 i=0
15 for source in `ls ${SOURCE_DIR}/js/*.coffee | sed -e "s:^.*\/\(\w*\).coffee:\1:"`; do\
16 sources[i]="--input ${OUTPUT_DIR}/js/$source.js";\
17 i=$(i+1);\
18 echo "Compiling coffee script: $source.coffee";\
19 coffee -bo "${OUTPUT_DIR}/js" -c "${SOURCE_DIR}/js/$source.coffee";\
20 done;\
21 python2 ${CLOSURE_PATH}/bin/calcdeps.py --path ${CLOSURE_PATH}/../\
22 ${sources[0]} --compiler_jar ${CLOSURE_PATH}/bin/compiler.jar\
23 --output_mode compiled > ${OUTPUT_DIR}/compiled.js;
24 echo "Cleaning ${OUTPUT_DIR}/js"
25 @rm -rf ${OUTPUT_DIR}/js
So, I want to join an array to a string and export it to the command starting with python2 on line 21
. The problem is that I can't even access any value inside the sources
variable. When I replace line 21
with echo $${sources[0]}
, it outputs the --input output/js/main.js
which is the proper input.
What to do? Also, if you could point out any bash/Makefile guides, which aren't on gnu.org
(long = time consuming), I'd appreciate it. I have experience with programming with few languages, but very little with bash, so at this point, it makes me laugh.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试
[@]
:另请参阅:http://tldp. org/LDP/abs/html/arrays.html
Try
[@]
:see also: http://tldp.org/LDP/abs/html/arrays.html
在第 15 行之前插入
以显示执行的命令。您会发现的一个错误(不会影响
${source[0]}
)是它无法按照您的预期工作;而是写
- 将美元符号加倍,因为它在 makefile 中,并将括号加倍以获得算术扩展;或者更简单地
获得算术评估。
Insert
before line 15 to display the executed commands. One error (that doesn't affect
${source[0]}
) you will spot is thatdoesn't work as you seem to want it to; rather write
- double the dollar sign because it's in a makefile, and double the parentheses to get arithmetic expansion; or even simpler
to get arithmetic evaluation.