请原谅我,我编写 Linux 脚本的经验很少。好的,我想做的是重命名具有指定名称的文件的一部分,但我遇到的问题是我在 For 循环期间收到的错误是 0403-011 指定的替换对此命令无效 我不确定我在 for 循环中做错了什么,有人可以帮忙吗?
#Creates Directory
echo "Name of New Directory"
read newdir
if [[ -n "$newdir" ]]
then
mkdir $newdir
fi
echo $userInput Directory Created
echo
echo "Directory you wish to Copy?"
read copydir
if [[ -n "$copydir" ]]
then
#Copies contents of Specified Directory
cp -R $copydir/!(*.UNC) $newdir;
#Searches through directory
for file in $newdir/$copydir*; do
mv -v -- "$file" "${file/old/new}";
done
fi
最佳答案
您使用的是哪个版本的 ksh?
"${file//old/new}"
和 "${file/old/new}"
是 ksh93 中的有效语法。 .
如果你的环境是ksh88 不支持“${file//old/new}”
替换。
您必须使用 sed/tr 来替换模式。这是 sed 的示例。
mv -v -- "$file""$(echo ${file}|sed 's/old/new/')"
关于Linux 脚本; For循环重命名;脚本新手,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52877523/