Fadangalini
Fadangalini

Reputation: 25

Script is not running the command I wish

Wondering if anyone here can help with this problem. I have custom profiles for certain games that I wish to run but having problems.

In this example, I have a mega drive profile, and a mortal kombat profile. Below is my runcommand-onstart.sh file. I got some of the code from someone else I found here I think, but have made changes as it didn’t work for me. The script outputs to a log for test purposes. The text output to the log is correct, but doesn’t do what it should, see below:

#!/usr/bin/env bash

# Get system name
system=$1
emulator=$2
rom=$3
command=$4

# rom_bn receives $rom excluding everything from the first char to the last slash '/'
rom_bn="${rom##*/}"

# rom_bn receives $rom_bn excluding everything from the last char to the first dot '.'
rom_bn="${rom_bn%.*}"

rom_joined='"'$rom_bn'"'

# Write to Runcommand Log to test
echo emitter LoadProfileByEmulator "$rom_joined" $1 >> $HOME/start.log

emitter LoadProfileByEmulator "$rom_joined" $1

The command I wish to run is: emitter LoadProfileByEmulator "Mortal Kombat (World)" megadrive

The test log has the following line: emitter LoadProfileByEmulator "Mortal Kombat (World)" megadrive

But ledspicer loads the megadrive profile… like it can't read the "Mortal Kombat" bit. If I copy and paste that line from the log into terminal, ledspicer loads the Mortal Kombat profile as it should….

Many thanks for any help

Upvotes: 0

Views: 71

Answers (1)

Barmar
Barmar

Reputation: 780673

Quotes aren't processed in the expansion of variables, so when you add quotes to $rom_joined, those are being treated literally. But since the profile doesn't actually have quotes in its name, that doesn't work.

Just quoting the variable in the argument to emitter is enough to make it a single word. If you want the quotes in the log, do that in the echo command.

#!/usr/bin/env bash

# Get system name
system=$1
emulator=$2
rom=$3
command=$4

# rom_bn receives $rom excluding everything from the first char to the last slash '/'
rom_bn="${rom##*/}"

# rom_bn receives $rom_bn excluding everything from the last char to the first dot '.'
rom_bn="${rom_bn%.*}"


# Write to Runcommand Log to test
echo "emitter LoadProfileByEmulator '$rom_joined' '$system'" >> $HOME/start.log

emitter LoadProfileByEmulator "$rom_bn" "$system"

Upvotes: 1

Related Questions