所以我寫了一個代碼來比較檔案名中的某個數字是否大于 11,如果它大于它應該創建一個目錄。
-->Mainfolder
-->Jan
-->Huistaak1-HelloWorld_Jonas.De Preter.s.ua_poging_2019-11-12
-->Feremans
-->Huistaak1-HelloWorld_Len.Feremans.s.ua_poging_2019-11-10
...
代碼需要獲取所提供日期的日期,如果它高于 11,它會創建一個目錄“late_inzending”所以它應該看起來像這樣
-->Mainfolder
-->Jan
-->Huistaak1-HelloWorld_Jonas.De Preter.s.ua_poging_2019-11-12
-->late_inzending
...
我的代碼似乎不起作用
for dir in */
do
cut1=$(echo "$dir" | cut -f4 -d '_')
cut2=$(echo "$cut1" | cut -f3 -d '-')
declare -i x="$cut2"
declare -i y=11
if (( x > y))
then
mkdir late_inzending
fi
done
uj5u.com熱心網友回復:
就像是。
#!/usr/bin/env bash
for d in ./*/*/; do #: From main plus one level down
[[ ! -d "$d" ]] && continue #: If it is not a directory, skip it.
end="${d##*-}" #: To remain only the last 2 strings and a /, e.g. 12/
(( ${end%/} > 11 )) && #: Remove the trailing `/`, to remain only 12 and compare.
echo mkdir -p "$d"late_inzending #: Append the desired string to the directory and create it.
done
從內部執行
mainecho如果您對輸出沒問題,請洗掉。
上述答案的資源
引數擴展
殼牌算術
條件構造
help test
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/524794.html
下一篇:回圈執行每個子檔案夾中的命令
