我正在尝试编写一个程序,该程序采用文件名并在其上加上日期。所以我试图获取文件名本身和扩展名的子字符串。
我是 BASH 的新手,所以也许我在这里遗漏了一些东西,但是按照在线指南,这似乎应该可行-
#!/bin/bash
echo "Type filename in this dir"
read filename
file=`filename%.*`
end=`filename##*.`
today=`date +%d-%m-%y`
dated="${file}_${today}.${end}"
cat $filename > $dated
但是计算机返回这些错误-
./fileDater.sh: line 5: filename%.*: command not found
./fileDater.sh: line 6: filename##*.: command not found
如果这很重要,我正在 Windows 10 上使用 Ubuntu 子系统。