Skip to content

Discussion: history 6 -> history | tail -n 6 #626

@onlyphantom

Description

@onlyphantom

In Chapter 4.3 Turning Interactive Work into a Script, the author suggests using history 6 to retrieve / show the last 6 commands in our history:

For example, we can save the last six commands to summarize_all_books.sh:

$ history 6 > summarize_all_books.sh
$ cat summarize_all_books.sh

297 for x in ../data/*.txt; do echo $x;
  bash book_summary.sh $x Author; done > authors.txt
298 for x in ../data/*.txt; do echo $x;
  bash book_summary.sh $x Release; done > releases.txt
299 ls
300 mkdir ../results
301 mv authors.txt releases.txt ../results
302 history 6 > summarize_all_books.sh

history 6 is probably specific to specific flavours of Unix, and is not guaranteed to work. I propose to change it to history | tail -n 6 instead:

For example, we can save the last six commands to summarize_all_books.sh:

$ history | tail -n 6 > summarize_all_books.sh
$ cat summarize_all_books.sh
  1. This is also consistent with the book's previous chapters (specifically in 3.8.12).
  2. Much like head -6 may work in some flavours of Unix, head -n 6 is recommended in the book.

What do everyone think?

I'm not sure if this is a welcomed suggestion, so I didn't send in a PR but decided to open an issue instead, and maybe get some feedback as to what the authors think. If this is the wrong avenue, apologies in advance 🙏

Thank you for the work you put into this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussiondiscussion before a proposal

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions