User Controls

Bash: Unexpected end of file. Meh.

  1. #1
    Sophie Pedophile Tech Support
    Ok niggers i wrote a shellscript to help with kernel managementm i 'fi'd` all my `ifs` i `esac'd` call my cases and i did all my `done'a`.


    #!/bin/bash

    if [[ "$EUID" -ne 0 ]]; then
    echo "This script must be run as root" 1>&2
    exit 1
    fi

    function logo()
    { printf " _____ _____ "
    printf "| | |___ ___ ___| |___ ___ "
    printf "| -| -_| _| | | | | .'| |"
    printf "|__|__|___|_| |_|_|_|_|_|__,|_|_|"
    printf "\nKernMan - Kernel Management Assistant.\n"}

    logo

    function usage()
    { printf "\nKernMan is a script written for the purpuse of simplyfying Kernel Managenemt.

    Select the option 'List' to display all installed kernels/ Se;ect the option 'Purge' to display
    all kernels that can be removed and subsequently do so"}



    PS3='Please enter your choice: '
    options=("Usage" "List" "Purge" "Quit")
    select opt in "${options[@]}"
    do
    case $opt in
    "Usage")
    usage
    ;;
    "List")
    `dpkg -l linux-image-\* | grep ^ii`
    ;;
    "Purge")
    kernelver=$(uname -r | sed -r 's/-[a-z]+//')
    dpkg -l linux-{image,headers}-"[0-9]*" | awk '/ii/{print $2}' | grep -ve $kernelver

    printf "\nThese items will be deleted.\n"
    read -p 'Continue? Y/n ' choice

    if [[ $choice == "y" ]]; then
    sudo apt-get purge $(dpkg -l linux-{image,headers}-"[0-9]*" | awk '/ii/{print $2}' | grep -ve "$(uname -r | sed -r 's/-[a-z]+//')")
    else
    echo "Aborted"
    break
    exit 1
    fi
    ;;
    "Quit")
    break
    ;;
    *) echo invalid option;;
    esac
    done


    Why then do i get an unexpected end of file error?
  2. #2
    I read the title as "unexpected end of life"
  3. #3
    Sophie Pedophile Tech Support
    Originally posted by Hash Slinging Slasher I read the title as "unexpected end of life"

    That's funny, but not really helpful.
  4. #4
    Lanny Bird of Courage
    If your closing brace for a function is on the same line as a command it needs to be preceded by a semicolon. Personally I'd just move the closing braces for logo and usage to the next line.
    The following users say it would be alright if the author of this post didn't die in a fire!
  5. #5
    Lanny Bird of Courage
    also since `foo()` is not call syntax the keyword function isn't necessary, you generally choose between `function foo {...` and `foo() {...`, the former is arguably better style since there are no named arguments in bash the parens were mostly added just to make C programmers feel more at home.
    The following users say it would be alright if the author of this post didn't die in a fire!
  6. #6
    Sophie Pedophile Tech Support
    Dank, thanks Lan.
  7. #7
    Sophie Pedophile Tech Support
    Right.

    Final version if anyone is interested.

    #!/bin/bash

    if [[ "$EUID" -ne 0 ]]; then
    echo "This script must be run as root" 1>&2
    exit 1
    fi

    function logo()
    { echo " _____ _____ "
    echo "| | |___ ___ ___| |___ ___ "
    echo "| -| -_| _| | | | | .'| |"
    echo "|__|__|___|_| |_|_|_|_|_|__,|_|_|"
    printf "\nKernMan - Kernel Management Assistant.\n"
    }

    logo

    function usage()
    { printf "\nKernMan is a script written for the purpuse of simplyfying Kernel Managenemt.

    Select the option 'List' to display all installed kernels/ Se;ect the option 'Purge' to display
    1all kernels that can be removed and subsequently do so\n\n3"
    }



    PS3='Please enter your choice: '
    options=("Usage" "List" "Purge" "Quit")
    select opt in "${options[@]}"
    do
    case $opt in
    "Usage")
    usage
    ;;
    "List")
    dpkg -l linux-image-\* | grep ^ii
    ;;
    "Purge")
    kernelver=$(uname -r | sed -r 's/-[a-z]+//')
    dpkg -l linux-{image,headers}-"[0-9]*" | awk '/ii/{print $2}' | grep -ve $kernelver

    printf "\nThese items will be deleted.\n"
    read -p 'Continue? Y/n ' choice

    if [[ $choice == "y" ]]; then
    sudo apt-get purge $(dpkg -l linux-{image,headers}-"[0-9]*" | awk '/ii/{print $2}' | grep -ve "$(uname -r | sed -r 's/-[a-z]+//')")
    else
    echo "Aborted"
    break
    exit 1
    fi
    ;;
    "Quit")
    break
    ;;
    *) echo invalid option;;
    esac
    done
Jump to Top