I'm trying to implement a script that lists a file one line at a time as a part of an experiment (I want to more or less duplicate the behavior of the cat function using other bash commands). Why would I want to do this? I finished my first script a couple of days ago and I just want to try something a bit more different. So here is what I have now:
last_line=$(tail -1 < whatever_file)
line_to_display=$(head -$line < whatever_file | tail -1)
echo "$line $line_to_display"
This, of course, should have the same result as cat -n whatever_file. It works fine but I'm wondering are there any shorter or simpler workarounds. I would be grateful if anyone bothers to outline or code his idea. I would really appreciate seeing the approach of someone more experienced than me.