linux - 简单循环读取显示哪一行正在读取的文本

标签 linux bash loops unix

我想得到哪一行正在读:

    #!/bin/bash
    for ip in $(cat ip.txt);
    do
        date
    done

最佳答案

试试这个:

#!/bin/bash

while read -r ip
do
  ((c++))
  echo $c
  date
done < ip.txt

关于linux - 简单循环读取显示哪一行正在读取的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29780120/

相关文章:

linux - 添加Iptables规则后无法访问端口号80和443

linux - Lua 不会执行 bash 脚本

java - linux bash中java程序超时

bash - 如何不敏感地检查文件相似度大小写

javascript - 如何制作动态函数?

java - continue 不能在循环外使用(实际上不在循环外)

arrays - Bash 数组操作

linux - accept() 创建一个新套接字是什么意思?

Bash - 如何将参数传递给通过标准输入读取的脚本

python - for y in range(y) 在 Python 中