Bash script newbie

im a newbie but trying to get this to work:
test.sh

#!/bin/bash
#cd /config/
wget http://user:[email protected]/tmpfs/auto.jpg -O /config/cameras/test.jpg
exit

when running this in terminal: bash test.sh it creates a file named TG1OA8~W for some reason
when running the wget command in terminal it creates the coorect test.jpg file.
when trying ./test.sh in terminal i get an error saying

bash: ./test.sh: /bin/bash^M: bad interpreter: No such file or directory
my goal is to run this every 10 secs to update a picture…
cannot get it to work

This sounds like you’re creating your script on a Windows machine and then transferring it to a hassio instance, right?

The problem is line endings. Windows and Linux use different characters to denote an end-of-line in a text file. You can read more about it in the Wikipedia entry for newline - Newline - Wikipedia

The best solution I’m aware of for hassio is to make sure you’re using an editor that can save as a Unix-style text file. I don’t use Windows enough to recommend one, sorry.

If you’re not actually using hassio, then you’ve got a few more options. Either use a text editor on the pi itself to write your script (I like nano for a beginner-friendly editor that can run in a terminal) or use a utility like dos2unix to convert the line endings for you.

1 Like

thank you!!!
i was using notepad++ on windows and after going into the menu and chose EOL conversion unix it worked!!

1 Like

Awesome, I’ll keep notepad++ in mind next time somebody asks about text editors for Windows. :smiley:

1 Like