I am trying to create a simple bash script that will launch an app from the command line and redirect STDOUT and STDERR output to /dev/null. I also want to include functionality that provides feedback if the script fails.
The script almost works, but I can’t get apps to launch in the background. I have tried using nohup, disown, wrapping the if statement in “(if…fi)&”, wrapping the else statement in “{… ;}&”, but everything I’ve tried has either introduced new problems or not worked at all.
Any suggestions?
Here is a basic version of what I’m doing:
#!/bin/bash
read -p "Enter program name: " APP
if
$APP 2>&1 | grep -q "command not found"
then
echo "That didn't work."
else
$APP >/dev/null 2>&1 &
fi
Well, you’re launching the application twice and I think the fist one is the one that’s hanging, when you’re checking if it exists by piping it’s output to grep. You probably want to do something like this Check if a program exists from a Bash script to check if it exists first instead of launching the application.