V
V
violet342019-01-16 11:23:12
bash
violet34, 2019-01-16 11:23:12

Reading from sh file?

I execute the following in the terminal:
for n in $*
do
count=` expr $count + 1`
done
I write the same thing to the sh-file, but the code is not read from the file, writes "syntax error next to the unexpected marker "$'do\ r'""
As far as I understand, before do there should not be a new line, but something else.
I suspect that the question is stupid, but I master it all in a hurry before the test, and there is no time to carefully google

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Movchan, 2019-01-16
@Alexander1705

In unix, a line feed is denoted by the symbol line feed (lf, \n, 0x0a, 10).
In windows - by the sequence carriage return + line feed (crlf, \r\n, 0x0d0a, 13 10).
Bash doesn't recognize carriage return and prints an error message.

T
Talik, 2019-01-16
@Talik0507

To get rid of special characters, then remove all spaces and carriage returns and restore the structure already in the OS in which it is supposed to work. (The most stupid and simple). Editors have special functions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question