It may be possible that there are invisible characters in the script. I have this behavior also seen, mostly when using editor from MS Windows. For me it helped to create the script once again from scratch.
For this small test script start with:
rpi ~$ cat > testscript.sh <<EOF
Then type the commands of your script and as last line EOF. When you finished typing it looks like this:
> #!/bin/sh > apt-get update > apt-get -y upgrade > apt-get dist-upgrade > EOF
A final Enter will copy it to testscript.sh. Check with cat testscript.sh. This ensures that only linux console characters are used. Then execute the script with:
rpi ~$ sudo bash testscript.sh Hit:1 http://raspbian.raspberrypi.org/raspbian stretch InRelease Hit:2 http://archive.raspberrypi.org/debian stretch InRelease Reading package lists... Done Reading package lists... Done Building dependency tree Reading state information... Done Calculating upgrade... Done 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. Reading package lists... Done Building dependency tree Reading state information... Done Calculating upgrade... Done 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. rpi ~$
As you can see, it works on my RasPi.
file NameOfYourScriptoutput? Copy the output it to your question.filecommand?