I have a simple code here but am having some trouble understanding it.
$ more $1 | head -$2 | tail -1
For the second parameter, I am running a test txt
$ more joe.txt
i am trying
something
else
to
see
if
head
works
the way
it
should
work
When I run the script I get the error:
$ ./sample.sh jad.txt joe.txt
head: invalid option -- 'j'
Try 'head --help' for more information.
It seems to work when I remove the -
in front of the $2
.
This is a practice question I found online and I doubt they made a mistake with this one. So either I'm missing something here am doing something wrong.
When I run it without the -
in front of $2
I get this:
./sample.sh jad.txt joe.txt
it
My questions here are:
- Why does it print "it" only when
tail -1
is used? To my understanding tail prints the last 10 lines. So what does the-1
do? - Is the
-
symbol supposed to do something in front of the$2
?