0

I have a file "release-1.0.0.jar" in the current working directory, and I'm trying to copy it to a directory "release_dir".

export t_version="1.0.0"

mkdir -p release_dir

cp release-${t_version}.jar release_dir

error: cp: cannot stat ‘release\\-1.0.0\r.jar’: No such file or directory

1

Your script was written on a Windows machine, or have aquired DOS line-endings some other way.

This means that each line of the script has an extra carriage return character (\r), which in turn means that the variable t_version has a value that is actually 1.0.0\r, and that the directory that you create will actually be called release_dir\r, etc.

Convert the script file to a Unix text file using dos2unix:

dos2unix myscript.sh

And also delete that erroneously named directory (assuming you use bash):

rmdir $'release_dir\r'
  • That explains the \r, but why \\-? – RalfFriedl Aug 11 '18 at 15:23
  • @RalfFriedl Unless the user is showing a modified script from what they ran, I can't really explain that. Note that the script as written would also generate two "command not found" errors for the carriage returns on the otherwise empty lines, so we're definitely are not seeing the script that was run. – Kusalananda Aug 11 '18 at 15:47
  • I don't criticize your answer, just wondering. – RalfFriedl Aug 11 '18 at 15:51
  • @RalfFriedl I didn't think you were, just explaining. – Kusalananda Aug 11 '18 at 15:53
  • I tried running these commands in redhat7 Linux machine command line terminal, not in windows. export t_version="1.0.0" mkdir -p release_dir cp release-${t_version}.jar release_dir I also tried your suggessted solution its still giving same error. – itgeek Aug 12 '18 at 23:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.