Automator bash unix 脚本,读取输入文件以移动单个文件或检测多个存档,然后移动存档
我有一个用 automator 制作的 Droplet,当我将文件放在应用程序图标上时,它会将文件移动到某个文件夹。
现在脚本看起来像这样:
for f in "$@"
do
cp "$f" "volumes/testdrive/testfolder/$(basename "$f")"
done
我想知道是否可以执行命令来检测是否将多个文件输入到脚本中,然后使用 zip 功能将它们存档并移动到同一文件夹,如果删除了单个文件,则将文件定期复制到指定的位置文件夹。
I have a droplet made with automator, which moves files when I drop them on application icon to certain folder.
now script looks like this:
for f in "$@"
do
cp "$f" "volumes/testdrive/testfolder/$(basename "$f")"
done
I was wondering if it possible to do command to detect if multiple files were input into script and then archive them with zip function and move to same folder, and if single file was dropped do regular copy of file to specified folder.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用条件,例如(语法可能有问题):
您不会希望使用 for 循环来执行此操作,因为那样它会经历为选择中的每个文件创建 zip 存档的繁琐操作。如果你正在做的是移动每一个,那么当然,使用一个循环,但你只是将它们全部取出并压缩它们
Use a conditional, something like (syntax might be way off):
You wouldn't want to do this with a for loop, because then it'd go through the rigmarole of creating a zip archive for each file in the selection. If what you were doing was moving each one, then sure, use a loop, but you're just taking them all and zipping them
$#
包含传递给脚本的参数数量。$#
contains the number of arguments passed to the script.