我想将其作为 Makefile 任务来实现:
# step 1:
curl -u username:password -X POST \
-d '{"name": "new_file.jpg","size": 114034,"description": "Latest release","content_type": "text/plain"}' \
https://api.github.com/repos/:user/:repo/downloads
# step 2:
curl -u username:password \
-F "key=downloads/octocat/Hello-World/new_file.jpg" \
-F "acl=public-read" \
-F "success_action_status=201" \
-F "Filename=new_file.jpg" \
-F "AWSAccessKeyId=1ABCDEF..." \
-F "Policy=ewogIC..." \
-F "Signature=mwnF..." \
-F "Content-Type=image/jpeg" \
-F "file=@new_file.jpg" \
https://github.s3.amazonaws.com/
但是,在第一部分中,我需要获取文件大小(以及内容类型,如果很简单,但不是必需的),因此存在一些变量:
{"name": "new_file.jpg","size": $(FILE_SIZE),"description": "Latest release","content_type": "text/plain"}
我尝试了这个,但它不起作用(Mac 10.6.7):
$(shell du path/to/file.js | awk '{print $1}')
有什么想法可以实现这一点吗?
最佳答案
如果您有 GNU coreutils:
FILE_SIZE=$(stat -L -c %s $filename)
-L
告诉它遵循符号链接(symbolic link);如果没有它,如果 $filename
是符号链接(symbolic link),它将为您提供符号链接(symbolic link)的大小,而不是目标文件的大小。
MacOS stat等效项似乎是:
FILE_SIZE=$(stat -L -f %z)
但是我没能尝试过。 (我将其编写为 shell 命令,而不是 make 命令。)您可能还会发现 -s
选项很有用:
Display information in "shell output", suitable for initializing variables.
关于shell - 如何在 Unix 上的 Makefile 中获取文件大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12065362/