Cp: cannot stat No such file or directory

Hi

Please review this script and let me know what i need to do.
This is my script

#!/bin/bash
#SCRIPT:  forms.sh
#PURPOSE: Process a file line by line with redirected while-read loop.
#PURPOSE: and copy the forms to the follder

foldername=sample_dir
mkdir -p $foldername

while read file;
do
FILENAME=$(basename $file)

LINE=$FILENAME
count=0

cp $LINE $foldername/
done < forms.txt

i have a file called forms.txt which contains unix directory path.
i want to extract the filename alone from the unix directory path. now i am having copy issue with this script.
This is the error, i am getting

cp: cannot stat `AKDAPREG.fmb': No such file or directory
cp: cannot stat `AKDATTRS.fmb': No such file or directory
cp: cannot stat `AKDFLOWB.fmb': No such file or directory
cp: cannot stat `AKDFLOWS.fmb': No such file or directory
cp: cannot stat `AKDOBFKS.fmb': No such file or directory
cp: cannot stat `AKDOBJWB.fmb': No such file or directory
cp: cannot stat `AKDOBPKS.fmb': No such file or directory
cp: cannot stat `AKDPICKF.fmb': No such file or directory
cp: cannot stat `AKDQUERY.fmb': No such file or directory

Please let me know your suggestions.

Thanks,
Rami Reddy.

Please check your file is present or not in current location where script is running.

Or better way use full path of a file to copy it :slight_smile:

Try to run the script in debug mode and let us know the result which you are getting.

#!/bin/bash
 
set -x

Hi vikram,

even though i tried in debug mode, i am not getting the copy to destination folder

Could you please post the line by line execution which took place after running your script in debug mode.

Are you sure those .fmb files are present in the same directory your script is running?

Also if you have correct absolute path of these files in form.txt , I suggest you to remove below line:

FILENAME=$(basename $file)

and perform copy:

cp "$file" "${foldername}/"