小编K. *_*ert的帖子

`while read -r line || 是什么意思 [[ -n $line ]]` 是什么意思?

不久前我发现了一些从文件中读取输入的代码,我相信来自 Stack Exchange,我能够适应我的需求:

while read -r line || [[ -n "$line" ]]; do
    if [[ $line != "" ]]
    then
        ((x++));
        echo "$x:  $line"
    <then do something with $line>
    fi
done < "$1"
Run Code Online (Sandbox Code Playgroud)

我现在正在检查我的脚本并试图了解它在做什么......我不明白这个语句在做什么:

while read -r line || [[ -n "$line" ]];

我知道 -r 选项表示我们正在将原始文本读入行,但我|| [[ -n "$line" ]]对语句的部分感到困惑。有人可以解释一下这是在做什么吗?

read

8
推荐指数
1
解决办法
3087
查看次数

标签 统计

read ×1