Syntax error: Bad fd number?
>&
is not syntax supported by sh
. You're explicitly using sh
as the shell in that script. You need to rewrite that line as:
wine "C:/D2GS/D2GS.exe" > /dev/null 2>&1 &
>&
is the csh syntax (also supported by zsh
and recent versions of bash
) to redirect both stdout and stderr to a file.
In sh
(Bourne (where it comes from) and POSIX), the syntax is:
if ! pgrep D2GS > /dev/null; then
wine C:/D2GS/D2GS.exe > /dev/null 2>&1 &
fi
(you've got the wrong ps/pgrep syntax as well; pgrep
doesn't read its stdin, so piping the output of ps
to it is pointless).
For completeness, the syntax to redirect both stdout and stderr in various shells:
> file 2>&1
: Bourne, POSIX and derivatives and fish>& file
: csh, tcsh, zsh and bash 4+ (though inzsh
andbash
only when the file name is not a sequence of decimal digits, otherwise it's the>&fd
Bourne redirection operator).&> file
: bash and zsh 3+> file >[2=1]
: rc and derivatives> file ^&1
: fish