我有一個 bash 檔案,我目前正在使用 if 陳述句檢查兩個檔案是否存在,然后再繼續其余檔案。
if [[ -e $flchck ]] && [[ -e $flchck2 ]]; then
--do stuff here
else
--sends me an email telling me the files were not found.
我的問題是,這是最有效的方法嗎?如果我需要它來檢查更多檔案,我會繼續添加 && 以包含更多檔案。
如果我想讓它告訴我在檢查時哪些檔案丟失了怎么辦?
任何有關如何處理此問題的指導/指示將不勝感激。
uj5u.com熱心網友回復:
通常人們會為此目的使用一個陣列。假設您的錯誤報告郵件代碼封裝在名為 的命令中send_error_email,這可能如下所示:
#!/usr/bin/env bash
files=( /path/to/file1 /path/to/file2 /path/to/file3 )
for file in "${files[@]}"; do
if ! [[ -e $file ]]; then
send_error_email "$file does not exist"
exit 1
fi
done
# do stuff here
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/517587.html
標籤:重击
下一篇:拆分包含多個分子的大檔案
