syntax error near Unexpected token `fi' Linux

Asked

Viewed 1,017 times

2

I’ve been trying to make a code to automate the steamcmd but always gave me this mistake syntax error near Unexpected token `fi', someone could 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
  • I managed to make the above code run without errors by removing the ! from within the if statements.

2 answers

3

It seems that there are missing spaces 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

1

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: https://developer.valvesoftware.com/wiki/SteamCMD#Downloading_SteamCMD

Browser other questions tagged

You are not signed in. Login or sign up in order to post.