Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Newline Madness in Bash Script

i have a bash script I edit on windows using UltraEdit and save as UTF-8 No BOM, using Unix Line Terminator style, as specified in the "save as" dialog box in UE.

I then upload it to a centos 5 x86 machine running parallels virtuozzo, and everytime, no matter how i upload it (FTP as binary file, or via parallels management console), the script wont work. When i view the script via parallels management console i see that the LAST, and ONLY the last line, has a weird character in it. If i remove the line terminator from the last line (let the script end at the last printable character) everything works fine.

My questions:

A) why is only the LAST line terminator causing problems?

B) how do i avoid this in the future?

thanks!

like image 860
Gaia Avatar asked Dec 23 '22 10:12

Gaia


2 Answers

firstly i would recommend you transfer as binary.. since you seem to know exactly the format you want..

ASCII/text FTP is known for doing line-ending conversion when you dont want it too.

like image 154
ShoeLace Avatar answered Jan 31 '23 07:01

ShoeLace


you can just run dos2unix to get rid of them..

like image 38
ghostdog74 Avatar answered Jan 31 '23 06:01

ghostdog74