shell script- syntax error: unexpected end of file

Discussion in 'Command Line' started by stratosam, Dec 5, 2012.

  1. stratosam

    stratosam New Member

    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hello, I am new to linux. I am currently trying Ubuntu and I was trying to write a shell script to perform automatic shutdown/reboot after some time (selected by the user). But it gives me the "syntax error: unexpected end of file" message. Here is the script:


    Code:
    #!/bin/bash
    
    echo "This script shuts down/reboots the computer"
    echo "Please select the prefered operation:
    1.Shutdown
    2.Reboot"
    read selection
    
    if (( ("$selection" == "1") ));then
    echo "Give the amount of minutes you want the computer to stay on before shutdown"
    
    read minutes
    sudo shutdown -h +"$minutes"
    
    else if (( ("$selection" == "2") ));then
    echo "Give the amount of minutes you want the computer to stay on before it reboots"
    
    read minutes
    su shutdown -r +"$minutes"
    
    
    fi
    
    In my earlier versions I tried to perform single operations, for example to get it to shutdown in 5 minutes. Until I added the "if" for the selection between shutdown and reboot I had no problems. I look it over and over for mistakes, but I can't see any. I don't know what it is. Can you help me please? Thank you in advance :)
  2. stratosam

    stratosam New Member

    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Ok, I solved the problem after all. It needed "elif" and 2 "fi" at the end.

Share This Page