0

I have a shell script working on SCO Unix 5.0.6. The problem is when I copy the script to another machine with SCO Unix 5.0.7 (and also other OS) then it is not running. It shows a syntax error.

Note that when I copy all instructions and paste them in command line then they work perfectly. However, as I said they are not working as one script file.

As example in the script I have:

case "${MODUS}" in

And I get the below error:

syntax error near unexpected token '$'in\r''

Base on the error it seems to me something is added at the end of each instruction.

In some cases when the error is at the end of the instruction I can fix the problem. I add a space and #(to consider the rest line as comment) at the end of each instruction. Then it works. However, the problem is that I cannot do that for all instructions. In some cases the error is in middle of the instruction and then (space#) not working.

Please let me know what is the reason for the error and how can I fix that.

1 Answer 1

4

Looks like your script has DOS line endings, the error even mentions it: in\r. You need to remove them.

Sign up to request clarification or add additional context in comments.

8 Comments

How can I prevent this, when I copy the file?
Don't use Notepad to "copy" files? You didn't say how are you doing the copying.
No, I don't think you do.
You can strip trailing carriage returns with sed -i 's/\r$//' file
@glennjackman - are you sure that GNU sed notation works in SCO Unix's sed? I'm suspicious of the -i without a null OPTARG, as well as support for \r.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.