已掉线,重新登录

首页 > 绿虎论坛 > 历史版块 > 编程 > Shell脚本

标题: 【更新】shell 中的sleep问题

作者: @Ta

时间: 2019-06-01发布,2019-06-01修改

点击: 5558

tasklist.txt文件里面就只有三行
1
2
3
最新修改:
请问下面两段代码有什么不一样的:
代码一:
#以行读取
oldIFS=$IFS;
IFS=$'\n';
for line in $(cat tasklist.txt )
do
echo $line
nohup mpirun -np 1 ./bin/ASDMPI cff &
sleep 1
done
kill -9 $(pgrep ASDMPI)

以上代码输出
1
nohup: appending output to 'nohup.out'
2
nohup: appending output to 'nohup.out'
3
nohup: appending output to 'nohup.out'




代码二:
cat tasklist.txt | while read line
do
echo $line
nohup mpirun -np 1 ./bin/ASDMPI cff &
sleep 1
done
kill -9 $(pgrep ASDMPI)


以上代码输出
1
nohup: appending output to 'nohup.out'


测试环境为:Ubuntu18.04

[隐藏样式|查看源码]


『回复列表(4|隐藏机器人聊天)』

1. up
(/@Ta/2019-06-01 20:15//)

2.

@冰封,结果是一样的啊,不一样肯定是你的tasklist.txt发生了变化,要不然就是你的shell解释器不标准,试试执行的时候前面加bash。

(/@Ta/2019-06-02 20:28//)

3. @老虎会游泳https://www.v2ex.com/t/569731
https://stackoverflow.com/questions/56406771/how-to-sleep-in-shell

我在其他两个平台提问的,听他们感觉是我的ASDMPI吃掉了管道的内容,但是为何在;另一台centos中不会发发生这种情况?在我的Ubuntu则会出现
(/@Ta/2019-06-03 12:19//)

4.

@冰封,由于在我这里没有复现该问题,所以我无法猜测。不过,我发现用 /bin/sh 运行你的第一个脚本结果不正确,可能是它不支持IFS。建议显式通过bash执行脚本来保证解析器一致。

(/@Ta/2019-06-03 14:38//)

回复需要登录

9月13日 03:09 星期六

本站由hu60wap6驱动

备案号: 京ICP备18041936号-1