我无法给出太多解释,因为我的英语很糟糕。我想要做的示例如下;
尝试.sh
#!/bin/sh
echo -n "Enter the port:"
read ports
if [ ! -d "$ports" ]; then
mkdir -p /root/port$ports
echo "The folder was created for $ports"
wget -q www.example.com/example.tar.bz2
tar -xjf example.tar.bz2
su root -c "screen -A -m -d -S 'example$ports' ./example -RunningAsRootIsEvilAndIKnowThat"
echo "$ports started."
else
exit 0
fi
腻子;
root@ubuntu:~# sh try.sh
Enter the port: 4445, 4546
Created folder 'port4445'
Created folder 'port4546'
4445 started.
4546 started.
我该如何制作?
最佳答案
#!/bin/bash
IFS=, read -p "Enter the Hosts: " -ra hosts </dev/tty
IFS=, read -p "Enter the Port: " -ra ports </dev/tty
for host in "${hosts[@]}"; do
for port in "${ports[@]}"; do
nc -vz $host $port
done
done
运行时:
bash try.sh
Enter the Port: 80
Enter the Hosts: 127.0.0.1
localhost [127.0.0.1] 80 (http) open
nc -vz $host $port
将检查 $host
是否正在监听 $port
IFS=,
分割输入,在我们的例子中使用 ,
将其视为输入分隔符。
-p
显示消息。
-a
将输入放入数组
关于linux - shell 脚本 - 如何进行多次读取?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42549714/