我不能给出太多解释,因为我的英语不好。我想做的例子如下:
try.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.
我该怎么做?
答案 0 :(得分:2)
#!/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
将输入放入数组
答案 1 :(得分:-2)
使用$ *来读取参数:
echo $* | awk '{ i=1; while(i<=NF) { print $i; i++; } }'
或
for i in $*; do
echo $i
done