What the reason the number of lines differs?
$ head -n 100000 ./access.log > ./data/log.sample
$ cat $_ | wc -l
1933424
bashio-redirection
What the reason the number of lines differs?
$ head -n 100000 ./access.log > ./data/log.sample
$ cat $_ | wc -l
1933424
Best Answer
$_
is expanding to./access.log
(last argument of the last executed command), not./data/log.sample
.So you are actually seeing the number of lines of
./access.log
.The redirection (
>
) is not part of thehead
command as it is done by the shell before thehead
command is even started. Hence with$_
you would get./access.log
.From
man bash
: