I'm trying to pass the arguments when invoking a bash script to a function defined in that script. In my head this is trivial but in practice seems more difficult.
Script is:
#!/bin/bash
function run_wine
{
WINEPREFIX=/disk1/.wine-ptgui WINEDLLOVERRIDES=mscoree=d /software/wine/1.7.42/linux.centos6.i386/bin/wine /disk1/.wine-ptgui/drive_c/Program\ Files/PTGui/PTGui.exe "$@"
}
# Check if we already have the wineprefix installed
if [ -d /disk1/.wine-ptgui ]; then
prefixExist=1
echo "$@"
run_wine "$@" &
sleep 5
exit 0
else
echo "no wineprefix"
exit 1
fi
I invoke the script with
./ptgui -batch -x /folder/project.pts
and can see my arguments echoed by the line echo "$@
but the arguments dont appear to be passed to the function, as the program exectutes as if no arguments had been given. So the program execution works, but the arguments don't appear to be passed.
However if i execute in the shell the command called by the 'run_wine' function with arguments, the program launches as I would expect, ie -
$ WINEPREFIX=/disk1/.wine-ptgui WINEDLLOVERRIDES=mscoree=d /software/wine/1.7.42/linux.centos6.i386/bin/wine /disk1/.wine-ptgui/drive_c/Program\ Files/PTGui/PTGui.exe -batch -x /folder/project.pts
The above command in my shell works just fine.
Am I escaping something incorrectly?
Edit: bash -x output
bryce-e@aw42e:dev$bash -x !!
bash -x ./ptgui -batch -x /folder/project.pts
+ '[' -d /disk1/.wine-ptgui ']'
+ prefixExist=1
+ echo -batch -x /folder/project.pts
-batch -x /folder/project.pts
+ sleep 5
+ run_wine
+ WINEPREFIX=/disk1/.wine-ptgui
+ WINEDLLOVERRIDES=mscoree=d
+ /software/wine/1.7.42/linux.centos6.i386/bin/wine '/disk1/.wine-ptgui/drive_c/Program Files/PTGui/PTGui.exe'
{{snipping out some wine messages here}}
+ exit 0
c:\\myapps\\foo.exe
– eyoung100 Aug 6 '15 at 22:59"c:\\Program Files\\PTGui\\PTGui.exe"
+ the@
. Properly escaping the path makes this easier to debug, ie the @ contains the file to open, but not the app to open it with, which is what everyone writing Answers is telling you. – eyoung100 Aug 6 '15 at 23:10echo ${WINEPREFIX}
andecho ${WINEDLLOVERRIDES}
as the last lines of your function. What gets echo'ed? When those echo correctly, add a Variable EXEPATH, then pass the entire Path + your options contained in the @ array. – eyoung100 Aug 6 '15 at 23:27