How to get the first line of a file in a bash script?
to read first line using bash, use read
statement. eg
read -r firstline<file
firstline
will be your variable (No need to assign to another)
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)