Bash mv不是目录

时间:2012-06-22 08:11:12

标签: bash mv

我的部分脚本是这样的:

while read line  
do 
code=`echo ${line}  | awk  '{print $1}'`
awk -f ${supscript}/rearrange.sh < ${base}/${code}  
mv temp_output* "$code"temp_output* 
done < filelist

脚本正在运行;唯一的问题是,当它尝试重命名文件时,我收到以下错误消息:

mv: target `pollcodetemp_output*' is not a directory

也许它与IFS有关。我尝试在脚本的开头指定:

IFS='
'

但它不起作用。我正在使用Windows文本编辑器,但我已经删除了CR。

2 个答案:

答案 0 :(得分:4)

最有可能的是,你只需要:

mv temp_output* "$code"

这会将当前目录中名为temp_output*的文件移动到变量$code中指定的目录。

但是,如果$code是文件,那么您需要查找rename命令(有多个版本,具有不同的语法),或者您需要使用内部循环:

for file in temp_output*
do mv "$file" "$code$file"
done

答案 1 :(得分:2)

您正在尝试将多个文件移动到不是目录的名称,这是不可能的。发生这种情况是因为您似乎尝试从通配符模式重命名为通配符模式,这也是不可能的。我不会猜测你到底想要完成什么,所以我不能给你任何额外的建议。