Create an automatically closing ssh tunnel to a host running VirtualBox and connect to a VirtualBox VRDE or internal Windows VM RDP server using freerdp, modifying window size to suit display and ssh and freerdp to suit network speed. Example of building up command line arguments in arrays and the properly expanding them on the command line of the program.
declare -a ssh_opts=(-f "-L $port:127.0.0.1:$port" -N)
declare -a ssh_non_opts=("$hostname")
declare -a xfreerdp_opts=("/u:$user" /cert-ignore +clipboard)
declare -a xfreerdp_non_opts=("/v:localhost:$port")
case "$display_scheme" in
'1920x1080_display' )
xfreerdp_opts+=(/size:1900x1000)
;;
'1600x1200_display' )
xfreerdp_opts+=(/size:1550x1100)
;;
* )
printf "Unrecognized display scheme '%b'.\n" "$display_scheme" >&2
exit 1
;;
esac
case "$network" in
'lan' )
;;
'wan' )
ssh_opts+=(-C)
xfreerdp_opts+=(/bpp:16 /network:modem /compression)
;;
* )
printf "Unrecognized network '%b'.\n" "$network" >&2
exit 1
;;
esac
ssh ${ssh_opts[*]} ${ssh_non_opts[*]} || (
printf "ssh failed creating tunnel.\n" >&2
exit )
xfreerdp ${xfreerdp_opts[*]} ${xfreerdp_non_opts[*]}