I'm writing a shell script that determines some variables, e.g. an open port. Then it opens some tmux windows, in which python programs are executed. These python programs should take the port as a command line argument, as such:
# Ports between 49152 - 65535 are usually unused.
port=$(shuf -i '49152-65535' -n '1')
# Then check if port is open
if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null ; then
# There is no service currently running on this port
echo "Using port: $port"
tmux new-session -d -s '1' 'python server.py -p $port'
tmux split-window -v -t '1' 'python client.py -p $port'
tmux split-window -h -t '1' 'python client.py -p $port'
Single quote doesn't allow variable expansion, use double quote:
tmux split-window -v -t '1' "python client.py -p $port"