LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   bash script - don't understand error (https://www.linuxquestions.org/questions/linux-newbie-8/bash-script-don%27t-understand-error-4175438483/)

itsnew2me 11-23-2012 05:17 PM

bash script - don't understand error
 
1 Attachment(s)
I wrote my first shell script to copy files for backup:

#!/bin/bash
cp /media/A2AC7FD5AC7FA289/zip/Rohan.ts /media/KINGSTON/Store
cp /media/KINGSTON/Store/roback.tc /media/A2AC7FD5AC7FA289/zip

The commands work when typed individually at a terminal, but when I run the script, I get an error about 'invalid argument', because it seems that \r has been appended to the original line. See attached screenshot.

What am I missing?

mohitnarula 11-23-2012 05:22 PM

Wrong Slash probably?
 
I just had a quick look and the first thing I noticed is you got a forward slash instead of a Backward slash, try changing that and see if it works.

Mohit

Quote:

Originally Posted by itsnew2me (Post 4835774)
I wrote my first shell script to copy files for backup:

#!/bin/bash
cp /media/A2AC7FD5AC7FA289/zip/Rohan.ts /media/KINGSTON/Store
cp /media/KINGSTON/Store/roback.tc /media/A2AC7FD5AC7FA289/zip

The commands work when typed individually at a terminal, but when I run the script, I get an error about 'invalid argument', because it seems that \r has been appended to the original line. See attached screenshot.

What am I missing?


schneidz 11-23-2012 05:24 PM

did you edit the script in windows.
ms new-lines are different from *-nix new-lines.

shivaa 11-23-2012 07:49 PM

Code:

cp /media/A2AC7FD5AC7FA289/zip/Rohan.ts /media/KINGSTON/Store
In screenshot, it's mentioned $'/media/KINGSTON/Store'. Did you check that dir. /media/KINGSTON/Store exists or not? If it's existing then simply use it's full path in script, not with a $:
Code:

cp /media/A2AC7FD5AC7FA289/zip/Rohan.ts /media/KINGSTON/Store
cp /media/KINGSTON/Store/roback.tc /media/A2AC7FD5AC7FA289/zip


itsnew2me 11-24-2012 07:57 AM

That solved it!
 
It was indeed the problem with Windows line endings instead of Linux.


All times are GMT -5. The time now is 11:19 AM.