2016-11-11 71 views
1

我想写使用Mac OS文本编辑小bash脚本,将赶在终端的用户输入和基于命令行虽然(JPG或GIF)规定的文件类型,通过迭代我的桌面命名dir1,扳指文件类型的所有文件和一个名为dir2捕捉用户输入要运行脚本

即用户类型JPG到终端新目录中放置这样和脚本踢成生活和拉都位于dir1的JPG文件的目录在dir2

地方,那是什么我是新的T实现这一意识的最瘦的和最令人费解的方式o shell脚本。

我即将达到药物。我可以对下面的代码做些什么来实现它的功能。

#!/bin/bash 

echo “Good Morning, Please enter your file type for sorting [ENTER]:” 
read $FILE 
if [[ $file == *.jpg ]]; then 
    mv ~/DIR1/*jpg* ~/Users/christopherdorman/desktop/dir2/ 
echo “your files have been successfully processed” 
fi 
+0

你需要使用$文件中的if语句,因为是bash区分大小写。 – Joel

+0

我部署了$但我正在逐渐指出“第10行的错误消息:语法错误附近意外的标记'做” –

回答

1

这里有一些关于bash变量和语法的混淆。您需要使用fi关闭您的if语句而不是done。另外,由于bash区分大小写,因此您需要在if语句中使用变量大写。我相信这是你在找什么(假设你的输入为“JPG”或“GIF”):

#!/bin/bash 

echo “Good Morning, Please enter your file type for sorting [ENTER]:” 
read FILE 
if [[ $FILE == "jpg" ]]; then 
    mv ~/DIR1/*jpg* ~/Users/christopherdorman/desktop/dir2/ 
    echo “your files have been successfully processed” 
fi 
+0

乔尔我认为这是沿着一个好一点帮助它我得到now.mv:重命名/用户/ christopherdorman/DIR1/* jpg *到/ Users/christopherdorman/Users/christopherdorman/desktop/dir2 / –