[英]i'm trying to write a bash script and i don't get the result displayed in the terminal
i'm trying to display the 3rd to the 7th line from a file but i get nothing displayed in the terminal i'm using this command : 我正在尝试从文件中显示第3行到第7行但是我在终端中没有显示任何内容我正在使用此命令:
head -n 7 /etc/passwd | tail -n +3
i want the result be seen in the terminal . 我想在终端看到结果。
You can try this way 你可以试试这种方式
head -n 7 /etc/passwd | tail -n 5
For example : 例如 :
seq 20 | head -n 7 | tail -n 5
Output : 输出:
3
4
5
6
7
Explanation : 说明:
head -n 7 -- print the first 7 lines ( so 1..7 printed)
tail -n 5 -- print last 5 lines ( so skipped first two lines 3..7 printed )
head -n 7 /etc/passwd | tail -n +3
Seems to do exactly what you want it to do for me. 似乎完全按照你的意愿为我做。 Have you verified the contents of /etc/passwd?
你验证了/ etc / passwd的内容吗? If you do not have permission to read the file or it is empty you will get no output.
如果您没有读取文件的权限或者它是空的,则不会输出任何内容。
I would check other places in the script. 我会检查脚本中的其他地方。 Change the first line of your script to:
将脚本的第一行更改为:
#!/bin/bash -v
to have it echo the commands so you can make sure what you think is being executed actually is. 让它回显命令,这样你就可以确定你认为实际执行的是什么。
What do you get than ? 你得到了什么? Show the file output, but choose another file ;)
显示文件输出,但选择另一个文件;)
It sometimes helps to just change commands, try with either HEAD or TAIL twice, to come to the same result. 有时只需更改命令,尝试使用HEAD或TAIL两次,即可获得相同的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.