Bash Makefile 连接数组

发布于 2025-01-06 16:38:05 字数 1052 浏览 0 评论 0原文

我正在尝试为文件名数组提供一个路径,然后对它们执行某些操作并填充到字符串(格式正确)。这是代码/概念

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如何视而不见 2025-01-13 16:38:05

尝试 [@]

a=(1 2 3 4 5)
echo "${a[1]}" # == 2
echo "${a[@]}" # == 1 2 3 4 5

另请参阅:http://tldp. org/LDP/abs/html/arrays.html

Try [@]:

a=(1 2 3 4 5)
echo "${a[1]}" # == 2
echo "${a[@]}" # == 1 2 3 4 5

see also: http://tldp.org/LDP/abs/html/arrays.html

折戟 2025-01-13 16:38:05

要做什么?

在第 15 行之前插入

    set -x;\

以显示执行的命令。您会发现的一个错误(不会影响 ${source[0]})是它

      i=$(i+1);\

无法按照您的预期工作;而是写

      i=$((i+1));\

- 将美元符号加倍,因为它在 makefile 中,并将括号加倍以获得算术扩展;或者更简单地

      ((i=i+1));\

获得算术评估。

What to do?

Insert

    set -x;\

before line 15 to display the executed commands. One error (that doesn't affect ${source[0]}) you will spot is that

      i=$(i+1);\

doesn't work as you seem to want it to; rather write

      i=$((i+1));\

- double the dollar sign because it's in a makefile, and double the parentheses to get arithmetic expansion; or even simpler

      ((i=i+1));\

to get arithmetic evaluation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文