Bash mv 不是目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11152444/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 02:33:26  来源:igfitidea点击:

Bash mv not a directory

bashmv

提问by Jonathan Leffler

I have part of my script that goes like this:

我的脚本的一部分是这样的:

while read line  
do 
code=`echo ${line}  | awk  '{print }'`
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有关。我尝试在脚本的开头将其指定为:

IFS='
'

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

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

回答by Jonathan Leffler

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.

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

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

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

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

回答by lanzz

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 toa 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.

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