所以我有一个代码,它接受文件名的一部分,它是日期格式的,并检查这个数字是否大于11。所有的文件都遵循相同的命名主体,只有不同的名称和日期。->示例:
Huistaak1-HelloWorld_Jonas.De Preter.s.ua_poging_2019-11-12 (注意:该文件名是一个目录)
下面是我的代码,它接受最后两个数字,并将它们与11进行比较,如果数字高于它,则创建一个目录:
for d in ./*/*/; do
[[ ! -d "$d" ]] && continue
char=${d: -3}
(( ${char%/} > 11 )) &&
mkdir -p "$d"late_inzending
done我得到的问题是,当日期小于10时,它会将09和11进行比较。
09 > 11 -> 'utf-8‘编解码器无法解码位置为679的字节0xc8 :无效的连续字节
发布于 2022-11-01 21:45:40
我简单地使用sed修复了它。
#the string which I'm working with:
#Huistaak1-HelloWorld_Jolien.Peters.s.ua_poging_2019-11-12
for d in ./*/*/; do
char=${d: -3} #:Variable to get the last 2 numbers in this string(12/)
x=${char%/} #:Variable to remove the invisible "/"
y=$(echo $x | sed 's/^0*//')#:Incase there are leading zeros remove them
echo $y
(( "$y" > 11 )) && #Compare the numbers and if $y is bigger then make new directory
mkdir -p "$d"late_inzending
donehttps://unix.stackexchange.com/questions/723299
复制相似问题