? appended to filename while copying from a ssh

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












1















I am using the command cp error.log error$HOSTNAME.log



the command works properly while running it separately in a server, but if it is run as script which uses ssh I am getting a ? appended to the filename. In the script I am copying an error log locally using ssh from other server and in the name of arerro$HOSTNAME.log but this copies as arerror$HOSTNAME.log?










share|improve this question
























  • Try scp instead of ssh and cp

    – Milind Dumbare
    Mar 16 '15 at 14:36






  • 2





    Use dos2unix on your script. And is it really error one place, then arerro, then arerror?! Details like this can matter a lot.

    – wurtel
    Mar 16 '15 at 15:39
















1















I am using the command cp error.log error$HOSTNAME.log



the command works properly while running it separately in a server, but if it is run as script which uses ssh I am getting a ? appended to the filename. In the script I am copying an error log locally using ssh from other server and in the name of arerro$HOSTNAME.log but this copies as arerror$HOSTNAME.log?










share|improve this question
























  • Try scp instead of ssh and cp

    – Milind Dumbare
    Mar 16 '15 at 14:36






  • 2





    Use dos2unix on your script. And is it really error one place, then arerro, then arerror?! Details like this can matter a lot.

    – wurtel
    Mar 16 '15 at 15:39














1












1








1


0






I am using the command cp error.log error$HOSTNAME.log



the command works properly while running it separately in a server, but if it is run as script which uses ssh I am getting a ? appended to the filename. In the script I am copying an error log locally using ssh from other server and in the name of arerro$HOSTNAME.log but this copies as arerror$HOSTNAME.log?










share|improve this question
















I am using the command cp error.log error$HOSTNAME.log



the command works properly while running it separately in a server, but if it is run as script which uses ssh I am getting a ? appended to the filename. In the script I am copying an error log locally using ssh from other server and in the name of arerro$HOSTNAME.log but this copies as arerror$HOSTNAME.log?







shell-script filenames cp newlines






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 17 '15 at 0:54









Gilles

542k12810991616




542k12810991616










asked Mar 16 '15 at 14:22









Hussain KajaHussain Kaja

62




62












  • Try scp instead of ssh and cp

    – Milind Dumbare
    Mar 16 '15 at 14:36






  • 2





    Use dos2unix on your script. And is it really error one place, then arerro, then arerror?! Details like this can matter a lot.

    – wurtel
    Mar 16 '15 at 15:39


















  • Try scp instead of ssh and cp

    – Milind Dumbare
    Mar 16 '15 at 14:36






  • 2





    Use dos2unix on your script. And is it really error one place, then arerro, then arerror?! Details like this can matter a lot.

    – wurtel
    Mar 16 '15 at 15:39

















Try scp instead of ssh and cp

– Milind Dumbare
Mar 16 '15 at 14:36





Try scp instead of ssh and cp

– Milind Dumbare
Mar 16 '15 at 14:36




2




2





Use dos2unix on your script. And is it really error one place, then arerro, then arerror?! Details like this can matter a lot.

– wurtel
Mar 16 '15 at 15:39






Use dos2unix on your script. And is it really error one place, then arerro, then arerror?! Details like this can matter a lot.

– wurtel
Mar 16 '15 at 15:39











1 Answer
1






active

oldest

votes


















1














It's highly likely that the file name does not in fact contain a question mark. Rather, the ls command displays this instead of a non-printable character. Given that this character comes at the end of a file name which you specified in your script, it's probably a carriage return.



Why would you have a carriage return in your script? Because you edited it in a Windows editor. Windows represents newlines with the two-character sequence CR, LF (carriage return, line feed), whereas Unix uses just the LF character. So from Unix's perspective your script contains a line on which the last character is the ordinary character CR.



Either edit your script with a Unix editor, or use a Windows editor that allows you to save with Unix line endings.



To fix the files that you've already created, you can use the following command:



cr=$(printf 'r')
find . -name "*$cr" -exec sh -c 'for x do mv "$x" "$x%."; done' _ +





share|improve this answer























  • Thanks alot Gilles!! I will try to use a unix editor and will update the result.

    – Hussain Kaja
    Mar 17 '15 at 18:14










Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f190500%2fappended-to-filename-while-copying-from-a-ssh%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














It's highly likely that the file name does not in fact contain a question mark. Rather, the ls command displays this instead of a non-printable character. Given that this character comes at the end of a file name which you specified in your script, it's probably a carriage return.



Why would you have a carriage return in your script? Because you edited it in a Windows editor. Windows represents newlines with the two-character sequence CR, LF (carriage return, line feed), whereas Unix uses just the LF character. So from Unix's perspective your script contains a line on which the last character is the ordinary character CR.



Either edit your script with a Unix editor, or use a Windows editor that allows you to save with Unix line endings.



To fix the files that you've already created, you can use the following command:



cr=$(printf 'r')
find . -name "*$cr" -exec sh -c 'for x do mv "$x" "$x%."; done' _ +





share|improve this answer























  • Thanks alot Gilles!! I will try to use a unix editor and will update the result.

    – Hussain Kaja
    Mar 17 '15 at 18:14















1














It's highly likely that the file name does not in fact contain a question mark. Rather, the ls command displays this instead of a non-printable character. Given that this character comes at the end of a file name which you specified in your script, it's probably a carriage return.



Why would you have a carriage return in your script? Because you edited it in a Windows editor. Windows represents newlines with the two-character sequence CR, LF (carriage return, line feed), whereas Unix uses just the LF character. So from Unix's perspective your script contains a line on which the last character is the ordinary character CR.



Either edit your script with a Unix editor, or use a Windows editor that allows you to save with Unix line endings.



To fix the files that you've already created, you can use the following command:



cr=$(printf 'r')
find . -name "*$cr" -exec sh -c 'for x do mv "$x" "$x%."; done' _ +





share|improve this answer























  • Thanks alot Gilles!! I will try to use a unix editor and will update the result.

    – Hussain Kaja
    Mar 17 '15 at 18:14













1












1








1







It's highly likely that the file name does not in fact contain a question mark. Rather, the ls command displays this instead of a non-printable character. Given that this character comes at the end of a file name which you specified in your script, it's probably a carriage return.



Why would you have a carriage return in your script? Because you edited it in a Windows editor. Windows represents newlines with the two-character sequence CR, LF (carriage return, line feed), whereas Unix uses just the LF character. So from Unix's perspective your script contains a line on which the last character is the ordinary character CR.



Either edit your script with a Unix editor, or use a Windows editor that allows you to save with Unix line endings.



To fix the files that you've already created, you can use the following command:



cr=$(printf 'r')
find . -name "*$cr" -exec sh -c 'for x do mv "$x" "$x%."; done' _ +





share|improve this answer













It's highly likely that the file name does not in fact contain a question mark. Rather, the ls command displays this instead of a non-printable character. Given that this character comes at the end of a file name which you specified in your script, it's probably a carriage return.



Why would you have a carriage return in your script? Because you edited it in a Windows editor. Windows represents newlines with the two-character sequence CR, LF (carriage return, line feed), whereas Unix uses just the LF character. So from Unix's perspective your script contains a line on which the last character is the ordinary character CR.



Either edit your script with a Unix editor, or use a Windows editor that allows you to save with Unix line endings.



To fix the files that you've already created, you can use the following command:



cr=$(printf 'r')
find . -name "*$cr" -exec sh -c 'for x do mv "$x" "$x%."; done' _ +






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 17 '15 at 0:54









GillesGilles

542k12810991616




542k12810991616












  • Thanks alot Gilles!! I will try to use a unix editor and will update the result.

    – Hussain Kaja
    Mar 17 '15 at 18:14

















  • Thanks alot Gilles!! I will try to use a unix editor and will update the result.

    – Hussain Kaja
    Mar 17 '15 at 18:14
















Thanks alot Gilles!! I will try to use a unix editor and will update the result.

– Hussain Kaja
Mar 17 '15 at 18:14





Thanks alot Gilles!! I will try to use a unix editor and will update the result.

– Hussain Kaja
Mar 17 '15 at 18:14

















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f190500%2fappended-to-filename-while-copying-from-a-ssh%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay