0

I have been working in a shell at Ubuntu desktop, I also did a detailed spell check to it, after that I kept testing it and made sure every single line was working as intended, besides a couple directory mistakes (that will need to be changed in the server), everything seems OK

And now I'm trying to run it in a clean virtual machine with ubuntu server, so I mounted a shared folder to get access to my shell, gave permissions to execute to all users, and tried running it and surprise, it doesn't run at all

To get the interpreter to run the script i need to remove the first line #!/bin/bash and use source instead of ./ to run the shell (named master.sh)

And now that i can get it to run I keep getting this error

enter image description here

A common error for wrong syntax on if statements, that I know its been fixed by me and tested it using spellcheck

After that I tried to purge any other non Unix character using

enter image description here

I know for a fact that both OS are using BASH as an interpreter (I checked)

Here's an minimum example of the code of the 2 "IF conditions" that I can identify stopping the script, if anyone wants to look at it

#!/bin/bash
if [ -e DB_conf ]
    then
            read -p "Use DB_conf settings? [y/n]: " -n 1 -r
                if [[ $REPLY =~ ^[Yy]$ ]]
                then
                    STUFF
                else           #This is line 39
                    STUFF2 
                fi
    else        
        MORE STUFF
    fi

Why is ubuntu server showing this error but not the desktop one (where it actually works)?

  • 1
    The sed command to replace CRLF line endings with LF endings would be sed -i 's/\r$//' 02_master.sh – steeldriver Apr 24 at 22:29
  • @steeldriver just tested sed -i 's/\r$//' 02_master.sh seems to actually do something however i get a sed: couldn't open a temporary file ./sedC35t0D: Permission denied even after a chmod 777 to all the scripts in the folder, i think it might have to do with the virtual machine user not being the actual owner of the shared folder – GoatZero Apr 25 at 17:15
2

It looks to me like the sed command has too many or too few /, see the comment by @steeldriver for a better sed command.

Alternatively, you can open the script in vim and view non-printable characters with [esc] :set list to see if you have any carriage returns. If that isn't the issue we'll need more context in order to solve the bash error.

  • Agreed - if vim is not an option, the OP could use cat -A 02_master.sh to see line-endings and non-printing characters – steeldriver Apr 25 at 15:48
  • @steeldriver I also made sure no line-endings where present on every line, but i did it using nano, i might use vim to double check and verify twice – GoatZero Apr 25 at 17:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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