I'm trying to run this bash script
#!/bin/bash
cd /ftp/slake/FiveM/cfx-server
[ -d cache ] || mkdir cache
exec FXServer $SERVER_ARGS $*
but it says that FXServer doesn't exist
I'm new to linux so this might be a pretty dumb fails
I'm trying to run this bash script
#!/bin/bash
cd /ftp/slake/FiveM/cfx-server
[ -d cache ] || mkdir cache
exec FXServer $SERVER_ARGS $*
but it says that FXServer doesn't exist
I'm new to linux so this might be a pretty dumb fails
When you run an executable by name, such as FXServer
, your shell will look in all of the directories in the $PATH
variable and try to find an executable with that name in one of them. It will then execute the first one it finds. Since /ftp/slake/FiveM/cfx-server
is not in your $PATH
, the only way this would work is if you had the current directory (.
) in your $PATH
and it looks like you don't. The simple solution is to just use the full path to the executable instead of just calling it by name:
#!/bin/bash
cd /ftp/slake/FiveM/cfx-server
[ -d cache ] || mkdir cache
./FXServer $SERVER_ARGS $*
./
means "the current directory" so that will execute the file called FXServer
that is in the current directory. I removed the exec
since that isn't needed and does something very specific.
A better version, assuming that this command needs to be run in the /ftp/slake/FiveM/cfx-server
, would be add a test and exit if for some reason we can't change to the right directory (for instance if it doesn't exist). Also, you should always quote your variables and you almost certainly want $@
and not $*
:
#!/bin/bash
if cd /ftp/slake/FiveM/cfx-server; then
[ -d cache ] || mkdir cache
./FXServer "$SERVER_ARGS" "$@"
else
echo "Failed to change directory to /ftp/slake/FiveM/cfx-server" >&2
exit 1
fi
exec ./FXServer $SERVER_ARGS $*
and/orexec /ftp/slake/FiveM/cfx-server/FXServer $SERVER_ARGS $*
. – Doug Smythies Nov 22 '20 at 16:14mkdir -p cache
is short for[ -d ... ] || ...
– Nov 22 '20 at 16:53