Search code examples
bashmv

Bash mv not a directory


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.


Solution

  • 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