簡體   English   中英

如何在 Bash shell 中的特定行中設置 output 的值?

[英]How can I output a value to a specific line in Bash shell?

如何將值打印到 Bash shell 中的特定行?
(例如,我想打印一個直到第 10 行的值。)

它不是特定於bash但您可以使用tput cup YX設置 cursor position:

tput sc         # save cursor position
tput cup 10 0
echo -n "hello"
tput rc         # restore cursor position

喲可以嘗試顯示文件的行號,並 grep 它為該行:

$ cat test 
A
B
C
$ cat test -n |grep ^"     2"
     2  B

$ cat test2
A
B
C
D
E
F
$ cat test2 -n |grep ^"     4"
     4  D

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM