TEMP=$(mktemp /tmp/temporary-file.XXXXXXXX) xterm -e bash -c "tty >$TEMP; sleep 24h" sleep 1 # give time for tty to run exec 9<$TEMP read -u 9 SLAVE_TTY exec 9<&- export SLAVE_TTY perl myRLprog.pl