Home > database >  How Do I Fix syntax error: unexpected end of file
How Do I Fix syntax error: unexpected end of file

Time:10-15

my code is

#!/bin/sh

clear

if [[ "$1" == "donut" ]]; then
    mkdir ~/.deb
    wget ``https://github.com/packageash/repo/blob/main/Donut.deb?raw=true ~/.deb
    dpkg --install ~/.deb/Donut.deb
    rm ~/.deb/Donut.deb
elif [[ "$1" == "nodonut" ]]; then
sudo rm /usr/local/bin/donut
else
echo "Nothing Picked To Install."

so how do i fix it and can i if i just try cause im trying to make a package manager in shell

CodePudding user response:

Well, if you are looking at only for two options and since this script is really simple, I would recommend changing the if to switch case, because the []s can have different behaviors depending if you are using bash/sh/zsh. I've created a simple snippet with that.

#!/bin/bash
DEB_FOLDER="${HOME}/.deb"

case $1 in

  donut)
    mkdir -p ${DEB_FOLDER} #try to create folder if it doesn't exists
    wget https://cdn.glitch.me/ec7fa70f-caec-4ba9-877f-3f809b43f7ea/Donut.deb -O ${DEB_FOLDER}/Donut.deb #save the wget downloaded file to ~/.deb/Donut.deb
    sudo dpkg --install ${DEB_FOLDER}/Donut.deb #install the deb package"
    rm -f ${DEB_FOLDER}/Donut.deb #removes the  ~/.deb/Donut.deb file"
    ;;

  nodonut)
    echo "sudo rm /usr/local/bin/donut"
    ;;

  *)
    echo -n "Nothing Pickedl To Install"
    ;;
esac

CodePudding user response:

So I Changed My Code Which Now Looks Like This How Do I Also Put Spaces In The Name That Downloads The Package?

#!/bin/sh

clear


case $1 in

  install-donut)
    sudo wget https://cdn.glitch.me/ec7fa70f-caec-4ba9-877f-3f809b43f7ea/Donut.deb 
    sudo mv ec7fa70f-caec-4ba9-877f-3f809b43f7ea/Donut.deb Donut.deb 
    sudo dpkg --install Donut.deb 
    sudo rm Donut.deb
    ;;

  uninstall-donut)
    sudo rm /usr/local/bin/donut
    ;;

  *)
    echo "Nothing Picked To Install"
    ;;
esac
  • Related