User Controls
Bash: Unexpected end of file. Meh.
-
2016-12-24 at 9:44 PM UTCOk 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? -
2016-12-24 at 9:59 PM UTCI read the title as "unexpected end of life"
-
2016-12-24 at 10:13 PM UTC
Originally posted by Hash Slinging Slasher I read the title as "unexpected end of life"
That's funny, but not really helpful. -
2016-12-24 at 10:28 PM UTCIf 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.
-
2016-12-24 at 10:32 PM UTCalso 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.
-
2016-12-24 at 10:39 PM UTCDank, thanks Lan.
-
2016-12-24 at 10:48 PM UTCRight.
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