Reputation: 1825
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
Upvotes: 1
Views: 517
Reputation: 47269
read
expects a variable after it to read into:
read var1
If you are only using read
to 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:
SERVER=server
SERVER_NAME=`echo $SERVER | sed 's#.*/\(.*\)#\1#g'`
because after that executes, SERVER_NAME
would just be the string server
If server
is a command on your environment, what you probably meant to do is:
SERVER_NAME=$(server | sed 's#.*/\(.*\)#\1#g'`)
Upvotes: 3