Shell scripts and line endings

Hopefully this will help someone …,

So this afternoon I wasted an hour or so when I was attempting to use one of my Linux bash scripts copied over to Haiku-OS. Basically it collects some system info into environment variables and then sends a payload with these values off to my mosquitto MQTT server. I can then monitor the client from anywhere. I used nano as an editor.

I ran the script and got all sorts of weird errors, such as “null value … missing” and truncated variable values. I adjusted parameters and turned echoing to screen on, and found that “/r” was being inserted and causing problems. It was then that I noticed that nano seemed to adding DOS line-ends. I installed and ran dos2unix which fixed the problem! I now need to check the nano line-end settings to avoid the problem in future. Hope this helps!

2 Likes

that sounds quite wierd. Haiku uses \n as line endings just like linux :g

perhaps this is a bug in the nano port (or it’s default config)
if so please open a bug at haikuports github Issues · haikuports/haikuports · GitHub

1 Like

Yeah, I was surprised. I’ll retest it with another script tomorrow and see if I get the same result.

I did some further testing today and could not reproduce the problem! It looks like the original file might have been edited on the source machine and accidentally saved with DOS line-ends. I edited new and old test files on the Haiku box and there were no problems! Case closed I think.

small side note, it is called haiku not haiku-os :slight_smile:

if you had transferred the scripts from windows, I would guess invisible special characters