如何获取文件的bash脚本的第一行? [英] How to get the first line of a file in a bash script?

查看:123
本文介绍了如何获取文件的bash脚本的第一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须把在bash变量的文件的第一行。我想这是grep命令,但它是任何方式限制的行数?

I have to put in a bash variable the first line of a file. I guess it is with the grep command, but it is any way to restrict the number of lines?

推荐答案

需要从文件中第一行和 -n 参数可以用来指定有多少行应提取:

head takes the first lines from a file, and the -n parameter can be used to specify how many lines should be extracted:

line=$(head -n 1 filename)

这篇关于如何获取文件的bash脚本的第一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆