1

This question already has an answer here:

i have an error that says line 17: unexpected end of file. i know others have already asked this, i tried to do the solutions given to them but still i am having the error. i am using ubuntu server 16.04 LTS. i used nano editor to write my bash.sh file. and i also downloaded the dos2unix already.

did the command sudo dos2unix bash.sh, it says converting file bash.sh to unix format...

after i do this i try to run again using sudo ./bash.sh usertest and i still have an error

my code is very simple just to test an argument:

USER=$1 
DATE=`date +%d%m%y` 
if [ -z "$1" ];then 
   echo "Wrong format"
   exit 1
else
   if [ -d "\home\$USERNAME" ]; then
     echo "correct"
fi

marked as duplicate by dessert, karel, Fabby, Eric Carvalho, vidarlo May 5 '18 at 21:08

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.

3

this is the code you posted (formatted):

  USER=$1 
  DATE=date +%d%m%y 
  if [ -z "$1" ];then 
    echo "Wrong format" 
    exit 1 
  else 
    if [ -d "\home\$USERNAME" ]; then 
        echo "correct" 
    fi

Hopefully, you can see when formatted this way, you are missing a "fi" at the bottom of the script.

  • OMG ! thanks , i missed out on that . now it works – Paul May 5 '18 at 6:35
  • 3
    Formatting helps in multiple ways. – TonyB May 5 '18 at 6:37

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