I have a shell script that I want to run two instances of my executable “server” in the background. However, when I run the script I get the error “read: missing arguments”. This problem does not occur when I remove the “&” to run in the background, but then it produces an undesirable behavior.
The server executable is followed by pairs of addresses and ports, but I removed any code checking for correct number of arguments. Where is the error being thrown, and how can I get this script to work?
#Location of executable.
SERVER=server
SERVER_NAME=`echo $SERVER | sed 's#.*/\(.*\)#\1#g'`
$SERVER localhost 4111 localhost 4222 &
$SERVER localhost 4222 localhost 4111 &
echo "Press ENTER to quit"
read
pkill $SERVER_NAME
readexpects a variable after it to read into:If you are only using
readto block the execution of the script until you receive some response from the user, just use the above suggestion.Also, this probably isn’t what you intend to do:
because after that executes,
SERVER_NAMEwould just be the stringserverIf
serveris a command on your environment, what you probably meant to do is: