答案1
-p 支持在一个命令中多次添加,因此我使用循环来一一添加端口
这是我的代码
set port_range $_flag_port
if echo $port_range | grep -qs -
set -e port_mapping_tcp
set -e port_mapping_udp
set -e port_mapping
set port_counter 0
for port_arrary in (seq (echo $port_range | awk -F "-" '{print $1}') (echo $port_range | awk -F "-" '{print $2}'))
set port_counter (math $port_counter+1)
set port_mapping_tcp[$port_counter] "-ptcp:$port_arrary"
set port_mapping_udp[$port_counter] "-pudp:$port_arrary"
end
else
if echo $port_range | grep -qs ,
set -e port_mapping_tcp
set -e port_mapping_udp
set -e port_mapping
set port_counter 0
for port_arrary in (echo $port_range | string split ,)
set port_counter (math $port_counter+1)
set port_mapping_tcp[$port_counter] "-ptcp:$port_arrary"
set port_mapping_udp[$port_counter] "-pudp:$port_arrary"
end
else
set port_mapping_tcp "-ptcp:$_flag_port"
set port_mapping_udp "-pudp:$_flag_port"
end
end
sudo systemd-nspawn --resolv-conf=off $port_mapping_tcp $port_mapping_udp -bnq -D $container