通过交互式脚本

时间:2016-11-26 14:15:02

标签: bash unix terminal

我在Mac上运行了一个正常运行的交互式脚本,用于对位于桌面上未排序文件夹中的文件进行排序和处理。

目前,用户在命令行中键入jpg,脚本执行并遍历未排序的文件夹,在该文件夹中获取这些文件类型,并在桌面上创建一个新目录并移动它们。

它的工作非常棒,但我想进一步开发脚本,以便我可以批量处理,而无需一次只输入一个终端命令。

即。我可以在终端jpg gif docx中输入一系列参数,脚本将运行并为jpg gif生成新的桌面目录{{1}并将所有这些文件类型移动到这样的文件中。

唯一需要注意的是,未排序文件夹中的剩余杂项文件(.wav png和一大堆其他扩展名)需要在桌面上创建一个docx文件夹,然后立即移入运行批处理。

实现这一目标的最简洁方法是什么?

miscellaneous

1 个答案:

答案 0 :(得分:1)

这样的事情应该有效:

read -a extensions -p "give me extensions seperated by spaces:  " # read extensions and put them in array $extensions
for ext in ${extensions[@]}; do  #for each extension stored in the array extensions
echo -e "- Working with extension $ext"
destination="/Users/christopherdorman/desktop/folder$ext"
mkdir -p "$destination"
mv  -v unsorted/*.$ext "$destination"
done

miscellaneous="/Users/christopherdorman/desktop/miscellaneous"    
mv  -v unsorted/*.* "$miscellaneous"; 
# since previously you moved the required extensions to particular desktop folders
# move what ever is left under unsorted folder to the desktop miscellaneous folder