bash - How to write a tail script without the tail command -
how achieve in bash. it's question got asked in interview , think of answers in high level languages not in shell.
as understand it, real implementation of tail seeks end of file , reads backwards.
the main idea keep fixed-size buffer , remember last lines. here's quick way tail using shell:
#!/bin/bash size=5 idx=0 while read line arr[$idx]=$line idx=$(( ( idx + 1 ) % size )) done < text ((i=0; i<size; i++)) echo ${arr[$idx]} idx=$(( ( idx + 1 ) % size )) done
Comments
Post a Comment