0

I have my server running Ubuntu 18.04 LTS, I used it to host my personal stuff, stream media, bots and doing android builds. A month ago I saw some errors while executing the envsetup.sh script that is where it prepares the environment to start the build. Link to the script. This is the output:

miguel@mike-machine:/home/builds/sources/PixysOS$ . build/envsetup.sh 
bash: build/envsetup.sh: line 1: syntax error near unexpected token `$'{\r''
'ash: build/envsetup.sh: line 1: `function hmm() {

I tried executing it in my other machine (Manjaro 18 KDE) and didn't have problems, thats where I have been building temporarily. I think it is a bash problem, but I sudo apt-get install --reinstall bash, but I still get the same.

Zanna
  • 70,465

1 Answers1

2

This is almost certainly because you saved the script with DOS-style CRLF line endings.

Ex. given a minimal script file

$ cat bad.sh
function hmm() {
cat <<EOF
Run "m help" for help with the build system itself.
EOF
}

that has been saved with DOS line endings, as shown by the file command

$ file bad.sh
bad.sh: ASCII text, with CRLF line terminators

then

$ . ./bad.sh
bash: ./bad.sh: line 1: syntax error near unexpected token `$'{\r''
'ash: ./bad.sh: line 1: `function hmm() {

but

$ dos2unix bad.sh
dos2unix: converting file bad.sh to Unix format...
$ . ./bad.sh
$ hmm
Run "m help" for help with the build system itself.

You can find the dos2unix package in the Ubuntu universe repository - otherwise you can use sed to remove the \r characters or vi's set ff=unix for example.

steeldriver
  • 136,215
  • 21
  • 243
  • 336
  • I just synced the repository and didnt change anything. And it is working on manjaro and on other guys's pc. If I use dos2unix I would have to use it on all scripts of the it (that are so much). Thanks – MiguelNdeCarvalho Jan 07 '19 at 13:39
  • @MiguelNdeCarvalho you didn't mention syncing in your original question - if you are storing these scripts in a remote repository, and they are behaving differently on different machines to which you download/sync them, then I'd suggest looking first at the sync software/settings on the machines in question – steeldriver Jan 07 '19 at 14:39
  • Hey, I am here just to say that it fixed my problem. So the problem was on the repo. Really thanks for your help :D – MiguelNdeCarvalho Jan 07 '19 at 23:27