I am trying to write a script that is effectively doing "if the user-inputted argument equals any one value in an array, the run the associated program. Else if the whole list has been checked and there is still no match, then run the argument as it was inputted".
However, the script while I can explicitly tell the script to run css via the comment out last line AND echoing the output for when "css" is inputted as an argument yields the exact same string of text, the game does not run with the script just exiting out.
In other words: echo run "${path[$ctr]}"
when you use "css" as an argument for the script yields the exact same string of text as echo run "/cygdrive/c/Program Files (x86)/Steam/Steam.exe" -applaunch 240
, but run "/cygdrive/c/Program Files (x86)/Steam/Steam.exe" -applaunch 240
launches the game even though run "${path[$ctr]}"
with "css" as the argument does not.
Script in question:
#!/bin/bash
#Path to steam games for easy reference
steam="\"/cygdrive/c/Program Files (x86)/Steam/Steam.exe\" -applaunch"
#Names user will need to input
declare -a name=("beamng"
"bejeweled3"
"caode"
"citiesskylines"
"css"
"criticalannihilation"
"doom3"
"skyrim"
"skyrimse"
"fallout4"
"fate"
"theforest"
"goatsimulator"
"gtav"
"gutsandglory"
"hatred"
"il2"
"ksp"
"kingdomcomedeliverance"
"l4d2"
"lichdombattlemage"
"mafia2"
"magicka"
"nationred"
"nomanssky"
"poe"
"redfactionguerrilla"
"saltandsanctuary"
"scribblenauts"
"shadowarrior"
"civv"
"civvi"
"stanleyparable"
"starwarstfu"
"starbound"
"starboundunstable"
"swordwithsauce"
"tf2"
"terraria"
"uebs"
"universesandbox"
"wreckfest"
"wreckfestthrowasanta")
#Paths to the above programs
declare -a path=("$steam/BeamNG.Drive/BeamNG.drive.exe"
"$steam/Bejeweled 3/Bejeweled3.exe"
"$steam/Children of a Dead Earth/CDE.exe"
"$steam/Cities_Skylines/Cities.exe"
"$steam 240")
size=${#name[@]}
let "size-=1"
ctr=0
if [ "$1" != "-l" ]
then
for i in "${name[@]}"
do
#echo Checking if "$1" equals "${name[$ctr]}"
if [ "$1" = "${name[$ctr]}" ]
then
run "${path[$ctr]}"
echo run "${path[$ctr]}"
break
elif [ $ctr -eq $size ]
then
"$1"
break
fi
let "ctr+=1"
echo $ctr
done
fi
#run "/cygdrive/c/Program Files (x86)/Steam/Steam.exe" -applaunch 240