Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8498279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:21:33+00:00 2026-06-11T00:21:33+00:00

I hate the bash ‘history’ command. It never finds the history items I want.

  • 0

I hate the bash ‘history’ command. It never finds the history items I want. Sometimes I can get what I want with ‘history | grep XXX’ but often either the history is too long (400+ hits! yay) or too short (no hits. Boo).

I thought to myself, why dont I write a little ‘history helper’ command that lets me basically ‘star’ specific history items and make them always turn up in my history, with both a global star list and a cwd specific star list.

Sounds amazing. So I naively tried to read the history by doing this:

system("history > blah")
FILE *fp = fopen("blah", "r")

Oh, that didn’t work. Ah, I get it, the system() command runs in it’s own context and can’t access the bash history. Drats. Ok, so I’ll try reading ~/.bash_history

ba baaa~ Nope. That’s only got the history up until the last call to either a) history -w, or b) call to exit from the shell.

So, question: How can I programatically access the current bash history in C?

(NB. No, not what’s in ~/.bash_history, the current history, the exact output you see when you type ‘history’ from the prompt; also, why C you ask? why not…but really, because I already have a handy ncurses wrapper I was going to use to let me get fancy auto-completion and sub-selection history searching on normal terminals…)

Edit: Please, if you have something useful to contribute, I’m happy to hear it, but I get a little sick of comments like ‘you should read the bash history man pages’.

I have read them. There is nothing that allows me to ‘star’ a history item and have it always turn up in my history, and nothing that allows me to maintain a per-directory history context. These are things that history does not support. I appreciate this. That’s why I want to write a helper function, for my specific purpose. If you have a comment like “maybe you should read the history man pages some more”, please just hold it in, and don’t respond; it doesn’t really address my question. 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:21:35+00:00Added an answer on June 11, 2026 at 12:21 am

    The closest you can get is

    alias cmd="history | cmd"
    

    and read standard input from the application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hate these linker errors, any idea how I can get rid of them?
I hate using these because I can never find a tutorial for them. I
I hate generating an exception for things that I can simply test with an
I hate that google can not search for symbols. I saw this in some
i hate situations, when i can't explain the behavior of compiler. So help me
I hate to do this, but I just can't identify what I am doing
I hate how .NET Programs want you to download the .NET Framework to run
I hate decimal numbers. For 1.005 I don't get the result I expect with
I hate default select control, that's because it can't be styled in IE using
I hate IE, I only want to display an out-of-date browser notification to IE8

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.