syntax error near unexpected token 'fi' Linux

0

I had to try to make a code to automate steamcmd but I always got this error syntax error near unexpected token 'fi' , could someone help me?

Code:

STEAMCMDDOWN="https://steamcdn-a.akamihd.net/client/installer/steamcmd_linux.tar.gz"
STEAMDIR="~/steamcmd"
if [! -d "$STEAMDIR" ]; then
    mkdir "~/steamcmd"
    cd "~/steamcmd"
else
        if [! -f "steamcmd.sh" ]; then
        wget "$STEAMCMDDOWN"
            tar +xf "steamcmd_linux.tar.gz"
    else
        echo "steamcmd installed"
    fi
    exit
fi
    
asked by anonymous 15.07.2016 / 17:03

3 answers

0

I was able to make the above code run without errors by removing the ! from within the if statements.

    
18.07.2016 / 15:00
0

How about automating the thing in a more robust way:

#!/bin/bash

STEAM_INSTALL_DIR="steamcmd"
STEAM_INSTALLER_URL="https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz"
STEAM_INSTALLER_FILE="/tmp/steamcmd_linux.tar.gz"


function steam_remove()
{
    rm -fr "${STEAM_INSTALL_DIR}"
    echo "Steam removido com sucesso!"
}


function steam_install()
{
    if [ -f "${STEAM_INSTALL_DIR}/steamcmd.sh" ]; then
        echo "Steam jah instalado!"
        return
    fi

    mkdir "${STEAM_INSTALL_DIR}"

    wget --no-check-certificate "${STEAM_INSTALLER_URL}" -O "${STEAM_INSTALLER_FILE}"

    tar -zxvf "${STEAM_INSTALLER_FILE}" -C "${STEAM_INSTALL_DIR}/"

    echo "Steam instalado com sucesso!"
}

cd ~

case $1 in
    '--install')
        steam_install
    ;;

    '--remove')
      steam_remove
    ;;

    '--reinstall')
      steam_remove
      steam_install
    ;;

    *)
        echo "Erro de sintaxe: $0 [ --install | --remove | --reinstall ]"
    ;;

esac

#fim-de-arquivo#

Reference: link

    
22.07.2016 / 19:20
0

There seems to be a gap between the [! leave them like this [!.

STEAMCMDDOWN="https://steamcdn-a.akamihd.net/client/installer
/steamcmd_linux.tar.gz"
STEAMDIR="~/steamcmd"
if [ ! -d "$STEAMDIR" ]; then
    mkdir "~/steamcmd"
    cd "~/steamcmd"
else
    if [ ! -f "steamcmd.sh" ]; then
        wget "$STEAMCMDDOWN"
        tar +xf "steamcmd_linux.tar.gz"
    else
        echo "steamcmd installed"
    fi
exit
fi
    
21.09.2016 / 20:04