Bash mv not a directory

蓝咒 提交于 2019-12-08 01:32:10

问题


I have part of my script that goes like this:

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

The script is working; the only problem is that when it is trying to rename the file I got the following error message:

mv: target `pollcodetemp_output*' is not a directory

Maybe it is something related with the IFS. I try to specify this at the beginning of the script as:

IFS='
'

But it is not working. I'm using a Windows text editor but I have already removed the CR.


回答1:


Most likely, you just need:

mv temp_output* "$code"

This will move the files named temp_output* in the current directory to the directory specified in the variable $code.

However, if $code is a file, then you need to look for a rename command (there are several versions, with different syntaxes), or you need to use an inner loop:

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



回答2:


You are trying to move multiple files to a name that is not a directory, which is not possible. This happens because you seem to be trying to rename from a wildcard pattern to a wildcard pattern, which is also not possible. I won't be guessing what exactly you're trying to accomplish, so I cannot give you any additional advice.



来源:https://stackoverflow.com/questions/11152444/bash-mv-not-a-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!