For my classes we have all of our homeworks and assignments in a read only folder so I want to copy all those files (they aren't very big) to my personal folder on ssh login. I so far have been able to get the script to copy the files sometimes, but other times (always if I'm running it again to update my files), it puts everything into another directory of the same name but with a ? at the end. I stuck a --verbose and it says stuff like

`/homes/USERNAME/PUBLIC_FOLDER/project_descriptions' -> `/homes/USERNAME/PRIVATE_FOLDER/publicCP\r/project_descriptions'

I have no idea why it's adding a \r to things. The only directory that has no files in it is "projects" and that one copies over just fine every time. I've tried -r, -R, -rf, and -RF to no avail. Worst part is that I can't even use the files in this second publicCP directory because WinSCP (which I use to open pdf's in chrome) says

System Error.  Code: 123.
The filename, directory name, or volume label syntax is incorrect

which I guess is expected considering it shows both publicCP's as the exact same name. I'm at a complete loss for this, google is no help because it doesn't recognize punctuation and of course "-r" tells it to not search anything with "r".

I've also tried cd'ing into the private folder and copying everything sans full path but that didn't work either.

closed as off-topic by Christopher, Stephen Kitt, Jeff Schaller, Stephen Harris, Sparhawk Feb 6 at 8:24

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Christopher, Stephen Kitt, Jeff Schaller, Stephen Harris, Sparhawk
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    It sounds like somewhere along the line, a line feed (\r) is being appended to the name of the publicCP directory. Without seeing the script you reference, it's hard to say where that might be coming from. Can you edit the relevant parts of your script into your question? – DopeGhoti Feb 5 at 15:16
  • I don't think copying it would work, I opened the file in vim and it found nothing but notepad++ found carriage returns and line feeds at the end of each line except the "projects" line because that was the last line. As of now I have no way of removing them, but I'll keep looking. It's something hidden in the bytes of the lines so stackexchange would probably show everything as fine. – Neywiny Feb 5 at 15:31
  • Please show your script. If you used a Windows text editor to create your script you might have carriage return characters \r at the end of the lines. In this case try to use dos2unix your_script_file or use an editor that can convert the line endings to UNIX format, e.g. Notepad++. The ? characters you see when you run ls are non-printable characters, probably \r introduced by your script. – Bodo Feb 5 at 15:32
  • Again, it's in the encoding as you said, so this website wouldn't be able to show that. I tried the dos2unix and that worked. I was editing in notepad++, I'll have to set it to only do line feeds and not carriage returns. – Neywiny Feb 5 at 15:36
  • Including the script in the question wouldn't show the \r characters but it would allow us to explain where exactly the \r characters are appended to commands or file names. – Bodo Feb 5 at 15:42

needed to remove carriage return at the end of the lines, notepad++ added them because it thought it was right but linux didn't like it.

  • 1
    This does provide an answer to the question. – Stephen Kitt Feb 5 at 17:18
  • Um yeah I think I can answer my own question thank you. I just wanted to add this in to help either me in a few months when I forget or somebody else with the same issue. Thank you Stephen Kitt for seeing that. – Neywiny Feb 5 at 18:42

Because you're in class...

Here are a couple of places to find help from the command line.

The manual pages:

man cp man ssh

The info pages:

info cp info ssh

A couple of terms to lookout for:

cp -r switch to copy directories recursively.

"double quotes" For directory path / name that may have a space in it.

"/path/to my file/here/file.text"

To help with trouble shooting:

Make sure script starts with "shebang" #! /bin/bash or other shell than bash.

Use the command line the get you command correct before added to script.

Verify the mode of your script...

ls -la -- to see the mode.

sudo chmod a+x /path/file.sh -- to change the mode.

  • If you read the question you will see that there is a specific problem with \r characters. There is no need to give general help only because the question is related to homework. – Bodo Feb 5 at 15:38
  • ...unless the "general help" addressed the issue at hand. Is the line ending being passed because the path is not quoted? Does the command work from the cli before added to script? Is the command 'broken' between 2 lines in the text editor? – jc__ Feb 5 at 15:56

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