简体   繁体   中英

Shell script printing out “read: missing arguments”

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

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'`)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM