I have a following simple script called single-instance that executes the given command if there is no process under that command running. If I hard-code the command after the else statement, it has no trouble running, but if I substitute the hard-coded command with $1 or $@, I get no new instance of the command. Is there a security mechanism in bash to prevent such command?
#!/bin/bash
if ps ax | grep -v grep | grep $1 > /dev/null;then
wmctrl -xa $1
else
# works fine if I switch $1 to terminator
$1
fi
The if statement part works fine. I only get one instance of the process as long as I invoke it using this script.
> /dev/null
?