gpt4 book ai didi

linux - 将变量增加1 bash

转载 作者:太空宇宙 更新时间:2023-11-04 12:22:18 24 4
gpt4 key购买 nike

你好,我是bash和linux的超级新手,但我正在尝试修改一个脚本,我必须能够创建一个文件,在该文件中打印我所请求的内容,但端口号每次增加一个。
这就是我现在所拥有的,但它不起作用。

rm -rf /etc/squid_squid_user
touch /etc/squid_squid_user
IPADDRESS=$(wget ipinfo.io/ip -q -O -)
portid=10000
portid=(($portid+1))
clear
echo "Enter a username for your proxies."
read username
echo
echo "Enter a password for your proxies."
read password
htpasswd -cdb /etc/squid/squid_user $username $password
sudo tee -a proxies.txt <<EOF
$IPADDRESS:$portid:$username:$password
EOF

我希望输出像下面的示例
45.32.14.256:10001:test:run
45.32.14.256:10002:test:run
45.32.14.256:10003:test:run
45.32.14.256:10004:test:run
45.32.14.256:10005:test:run

最佳答案

我已经评论了您的原始代码的一些行,并引入了一个循环。

# Original code: IPADDRESS=$(wget ipinfo.io/ip -q -O -)
IPADDRESS=45.32.14.256

# Original code: variable number set earlier
read -p "How many proxies? " number
portid=1000
((maxport=portid+number))
while (( portid < maxport)); do
((portid++))
# original code: clear
echo "Enter a username for your proxies."
# original code: read username
username=test
echo
echo "Enter a password for your proxies."
# original code: read password
password=run
# Original code: htpasswd -cdb /etc/squid/squid_user $username $password
sudo tee -a /tmp/proxies.txt <<EOF
$IPADDRESS:$portid:$username:$password
EOF
done

关于linux - 将变量增加1 bash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45655405/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com