Issue
The following command work as anticipated independently:
fuser -k 12345/tcp
nodemon app
However
fuser -k 35243/tcp && nodemon app
just returns the result of the first command / returns to the command line.
Why can't these command be chained?
(Also attempted a sleep in between the commands)
Solution
https://man7.org/linux/man-pages/man1/fuser.1.html
fuser returns a non-zero return code if none of the specified files is accessed or in case of a fatal error. If at least one access has been found, fuser returns zero.
The &&
operator short-circuits and only executes the second command if the first one returned zero ("success"). So if the socket was not already in use, then fuser
returns nonzero and nodemon app
is not executed.
If you want to execute the second command regardless of the result of the first one, use ;
instead of &&
:
fuser -k 35243/tcp ; nodemon app
This would be exactly the same as listing them on two lines.
Answered By - Nate Eldredge