0

I made and tested this bash script on an ubuntu machine at my school and then I came home to use it on the windows 10 Bash and I am getting these errors:

./newflask.sh: line 8: syntax error near unexpected token `else'
'/newflask.sh: line 8: `    else

Here is the code:

 #!/bin/bash

if [ $# -eq 0 ]; then
      echo "No arguments supplied"
else
    if [ -d $1 ]; then
    echo "Directory exists"
    else 
        mkdir $1
        cd $1
        touch $1.py
        mkdir templates
        mkdir static
        mkdir utils
        mkdir data
        cd utils
        touch __init__.py
        cd ..
    fi
fi

Thanks

  • might try elif instead – Garr Godfrey Oct 02 '17 at 21:50
  • 4
    Notice on the 2nd line of the error message that there's a single quote in column 1? That means you have "else\r" which is causing the error. Run `dos2unix` on your script file, or `sed -i 's/\r$//' newflask.sh` – glenn jackman Oct 02 '17 at 22:33
  • Expanding on @glennjackman's diagnosis: DOS/Windows programs normally put a carriage return (aka CR, `\r`, or `^M`) followed by linefeed (aka newline, LF, `\n`, or `^J`) at the end of lines; unix programs only expect `\n`, and mistake the `\r` for part of the line's content. If you mix Windows and unix programs, you're going to have this problem *a lot*. My recommendations: learn how to get your Windows editors to save in unix format, get friendly with `dos2unix`, and use the `file` command to find out what format files are in. – Gordon Davisson Oct 02 '17 at 23:50

0 Answers0