1

I don't use linux very often, but I need to for this particular python project. Because of that, I'm trying to make an installer for my program using this shell script:

SETUP.sh

#!/bin/bash

apt-get update
apt-get install python3-pip -y
apt-get install python3-tk -y
pip3 install -r requirements.txt

after chmodding it to be executable, and running sudo sh SETUP.sh I get this output:

: notfound: SETUP.sh:
E: Invalid operation update
] is not known. option '
] is not known. option '
SETUP.sh: 6: SETUP.sh: pip3: not found

The weirdest part is all those commands work on their own if I just manually put them into the command line. What am I doing wrong?

marked as duplicate by wjandrea, dessert, pa4080, Zanna command-line Nov 22 '17 at 19:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Why exactly do you run a #!/bin/bash script with sh rather than bash? – dessert Nov 22 '17 at 17:14
  • 1
    @pa4080 the output of ./SETUP.sh is: bash: ./SETUP.sh: /bin/bash^M: bad interpreter: No such file or directory and yes, it's being run in the same directory it's saved in – Zaya Nov 22 '17 at 17:20
  • 3
    Hm. Where you write this script? Maybe in Windows? – pa4080 Nov 22 '17 at 17:24
  • 2
    ^M is the key here, you've got windows line endings! run dos2unix SETUP.sh, then redo chmod +x SETUP.sh. (sudo apt install dos2unix before using it....) – pim Nov 22 '17 at 17:33
  • 2
    @pim The linked question has solutions. I prefer the sed solution myself, cause you don't need to install anything. – wjandrea Nov 22 '17 at 17:38
2

Okay, it looks like the issue has something to do with me not knowing how to run shellscripts, and me porting the script over from a Windows machine. (Similar to this thread)

After re-writing it in vi, and running it with sudo ./SETUP.sh it works

  • Zaya, please accept this answer. – pa4080 Nov 23 '17 at 9:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.