我正在嘗試自動化一個進程,但希望使其更高效和更智能。我自動從我的電子郵件每日下載文件,電子郵件的命名約定如下:使用「like」通配符匹配文件名
pending_file_「CURRENT_DATE」的.xlsx
正如預期的那樣,將這個文件夾(如CURRENT_DATE MMDDYYYY,即pending_file_12082015.xlsx。)隨着大量名稱非常類似的文件變大,只有一個標題內的變化,在這種情況下,變化將是當前日期。
我想確保我搶對應於當前日的文件,這是我到目前爲止有:
cd Pending_File
date=$(date.exe +"%m%d%Y") #assigns the current date to the date variable in the form of mmddYYYY
if [[ -f *"$date"* ]]; then
scp pending_file_"$date".xlsx [email protected];
echo "I have successfully completed today's file!"
else
echo "Could not find today's file!"
fi
目前,如果我執行我的代碼,它總是執行else語句即使我的pending_file文件夾包含一個名爲pending_file_「current_date」.xlsx的文件。我的期望是date = 12082015,它也包含在文件pending_file_12082015中,因此if語句將返回true,因爲[-f 「$ date」]能夠匹配文件名中的日期字符串。
這是什麼調用'date.exe'(窗口之嫌)瘋狂的外殼,但認爲它可以做聰明的bash像事情? –
嗨馬克 - 不確定是否諷刺,嚴重關切或其他。我只是試圖自動執行日常任務,但我的shell知識幾乎沒有。 – CjRobin
這是一個問題。它是什麼外殼? –