生信喵 发表于 2024-12-12 21:01:25

SHELL4 输出第5行的内容

<h2>描述</h2>
<p>编写一个bash脚本以输出一个文本文件nowcoder.txt中第5行的内容。</p>
<p>示例:<br />
假设 nowcoder.txt 内容如下:</p>
<pre><code>welcome
to
nowcoder
this
is
shell
code
</code></pre>
<p>你的脚本应当输出:<br />
is</p>

生信喵 发表于 2024-12-12 21:01:51

<pre><code>#!/bin/bash
line=1
while read value
do
    if [ $line -eq 5 ]
    then echo $value
    fi
    ((line++))
done &lt; nowcoder.txt
</code></pre>
页: [1]
查看完整版本: SHELL4 输出第5行的内容